Pagini recente » Cod sursa (job #630072) | Cod sursa (job #2219501) | Cod sursa (job #1555689) | Cod sursa (job #1202811) | Cod sursa (job #531961)
Cod sursa(job #531961)
// http://infoarena.ro/problema/curcubeu
#include <fstream>
using namespace std;
#define maxSize 1000005
ifstream in("curcubeu.in");
ofstream out("curcubeu.out");
struct stuff {
int start,stop;
int color;
};
int nrHouses;
int t[maxSize];
int house[maxSize];
stuff toPaint[maxSize];
int main() {
in >> nrHouses >> toPaint[1].start >> toPaint[1].stop >> toPaint[1].color;
for(int i=2;i<=nrHouses;++i) {
toPaint[i].start = ((long long)toPaint[i-1].start * i) % nrHouses;
toPaint[i].stop = ((long long)toPaint[i-1].stop * i) % nrHouses;
toPaint[i].color = ((long long)toPaint[i-1].color * i) % nrHouses;
int aux = max(toPaint[i].start,toPaint[i].stop);
toPaint[i].start = min(toPaint[i].start,toPaint[i].stop);
toPaint[i].stop = aux;
}
for(int i=1;i<=nrHouses;++i)
t[i] = i + 1;
for(int i=nrHouses-1;i>=1;--i)
for(int k=toPaint[i].start;k<=toPaint[i].stop;) {
if(!house[k])
house[k] = toPaint[i].color;
int aux = k;
k = t[k];
t[aux] = toPaint[i].stop + 1;
}
for(int i=1;i<=nrHouses-1;++i)
out << house[i] << "\n";
in.close();
out.close();
return (0);
}