Mai intai trebuie sa te autentifici.
Cod sursa(job #85931)
Utilizator | Data | 23 septembrie 2007 11:45:05 | |
---|---|---|---|
Problema | Curcubeu | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Autumn Warmup 2007, Runda 2 | Marime | 1.24 kb |
using namespace std;
#include <cstdio>
#include <set>
#define lb lower_bound
#define up upper_bound
struct nod { int x, y, v; nod(){}; nod(int a,int b, int c){x=a; y=b; v=c;};};
struct cmp{
bool operator()(const nod &a, const nod &b)const
{
if(a.x<b.x) return 1;
if(a.x==b.x)if(a.y<b.y)return 1;
return 0;
}
};
set<nod,cmp>x;
int main()
{
freopen("curcubeu.in","r",stdin);
int n, a, b, c, a1, b1, c1;
scanf("%d %d %d %d\n", &n, &a,&b, &c);
int p, q;
p=a, q=b;
a=p<?q;
b=p>?q;
x.insert(nod(a, b, c));
set<nod, cmp>::iterator i1, i2, i3;
int t;
#define cont continue;
for(t=2;t<=n-1;++t)
{
a=(a*t)%n;
b=(b*t)%n;
c=(c*t)%n;
p=a;q=b;
a=p<?q; b=p>?q;
i1=x.lb(nod(a, b, c));
a1=i1->x;
b1=i1->y;
c1=i1->v;
if(b<a1) { x.insert(nod(a, b, c));cont;}
if(b1<a) { x.insert(nod(a, b, c));cont;}
if(a<=a1 && b>=b1){ x.erase(nod(a1, b1, c1)); x.insert(a, b, c);cont;}
if(a<=a1 && a1<=b && b<=b1){ x.erase(nod(a1, b1, c1)); x.insert(nod(a, b, c)); x.insert(nod(b, b1, c1));cont;}
// printf("%d %d %d\n", i1->x, i1->y, i1->v);
printf("%d %d %d\n",a,b,c);
}
return 0;
}