# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
962898 |
2024-04-14T09:29:07 Z |
serkanrashid |
Game (IOI13_game) |
C++14 |
|
1325 ms |
256000 KB |
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
struct Tnode
{
long long a;
Tnode *l, *r;
Tnode()
{
a = 0;
l = r = nullptr;
}
};
struct Tree
{
Tnode *A;
Tree *L, *R;
Tree()
{
A = nullptr;
L = R = nullptr;
}
};
Tree *Root = nullptr;
int r,c;
int Ql,Qr,ql,qr;
long long Pos,pos,val;
long long gcd3(long long a, long long b)
{
while(a&&b)
{
if(a>b) a %= b;
else b %= a;
}
return a+b;
}
long long merge1(Tnode *&t1, Tnode *&t2)
{
if(t1==nullptr&&t2==nullptr) return 0;
if(t1==nullptr) return t2->a;
if(t2==nullptr) return t1->a;
return gcd3(t1->a,t2->a);
}
void upd(Tnode *&t, int l, int r)
{
if(t==nullptr) t = new Tnode();
if(l==r)
{
t->a = val;
//cout << l << " " << r << " " << (t->a) << "upd" << endl;
return;
}
int mid = (l+r)/2;
if(pos<=mid) upd(t->l,l,mid+0);
else upd(t->r,mid+1,r);
t->a = merge1(t->l,t->r);
//cout << l << " " << r << " " << (t->a) << "upd" << endl;
}
Tnode *getA(Tree *&t)
{
if(t==nullptr) return nullptr;
return t->A;
}
long long geta(Tnode *&t)
{
if(t==nullptr) return 0;
return (t->a);
}
void Merge(Tnode *&t, Tnode *t1, Tnode *t2, int l, int r)
{
if(t==nullptr) t = new Tnode();
if(l==r)
{
t->a = gcd3(geta(t1),geta(t2));
//cout << l << " " << r << " " << (t->a) << "merge" << endl;
return;
}
int mid = (l+r)/2;
if(pos<=mid)
{
if(t1!=nullptr) t1 = t1->l;
if(t2!=nullptr) t2 = t2->l;
Merge(t->l,t1,t2,l,mid+0);
}
else
{
if(t1!=nullptr) t1 = t1->r;
if(t2!=nullptr) t2 = t2->r;
Merge(t->r,t1,t2,mid+1,r);
}
t->a = gcd3(geta(t->l),geta(t->r));
//cout << l << " " << r << " " << (t->a) << "merge" << endl;
}
void Upd(Tree *&t, int l, int r)
{
if(t==nullptr) t = new Tree();
if(l==r)
{
upd(t->A,0,c-1);
return;
}
int mid = (l+r)/2;
if(Pos<=mid) Upd(t->L,l,mid+0);
else Upd(t->R,mid+1,r);
//cout << "new Merge" << " " << l << " " << r << endl;
Merge(t->A,getA(t->L),getA(t->R),0,c-1);
}
void update(int P, int Q, long long K)
{
Pos = P;
pos = Q;
val = K;
Upd(Root,0,r-1);
//cout << ((Root->A)->a) << "after update" << endl;
}
long long query(Tnode *&t, int l, int r)
{
if(r<ql||qr<l||l>r) return 0;
if(t==nullptr) return 0;
if(ql<=l&&r<=qr) return t->a;
int mid = (l+r)/2;
long long ch1 = query(t->l,l,mid+0);
long long ch2 = query(t->r,mid+1,r);
return gcd3(ch1,ch2);
}
long long Query(Tree *&t, int l, int r)
{
if(r<Ql||Qr<l||l>r) return 0;
if(t==nullptr) return 0;
if(Ql<=l&&r<=Qr)
{
long long ch = query(t->A,0,c-1);
return ch;
}
int mid = (l+r)/2;
long long ch1 = Query(t->L,l,mid+0);
long long ch2 = Query(t->R,mid+1,r);
return gcd3(ch1,ch2);
}
long long calculate(int P, int Q, int U, int V)
{
ql = Q;
qr = V;
///
Ql = P;
Qr = U;
long long ans = Query(Root,0,r-1);
return ans;
}
void init(int R, int C)
{
r = R;
c = C;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
418 ms |
12772 KB |
Output is correct |
5 |
Correct |
300 ms |
12896 KB |
Output is correct |
6 |
Correct |
333 ms |
9808 KB |
Output is correct |
7 |
Correct |
377 ms |
9720 KB |
Output is correct |
8 |
Correct |
262 ms |
6704 KB |
Output is correct |
9 |
Correct |
365 ms |
9812 KB |
Output is correct |
10 |
Correct |
332 ms |
9336 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
664 ms |
15772 KB |
Output is correct |
13 |
Correct |
1059 ms |
6148 KB |
Output is correct |
14 |
Correct |
220 ms |
1164 KB |
Output is correct |
15 |
Correct |
1247 ms |
8816 KB |
Output is correct |
16 |
Correct |
160 ms |
18388 KB |
Output is correct |
17 |
Correct |
638 ms |
11464 KB |
Output is correct |
18 |
Correct |
1124 ms |
18600 KB |
Output is correct |
19 |
Correct |
871 ms |
18848 KB |
Output is correct |
20 |
Correct |
748 ms |
18096 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
396 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
476 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
496 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
426 ms |
12544 KB |
Output is correct |
13 |
Correct |
284 ms |
12848 KB |
Output is correct |
14 |
Correct |
346 ms |
9764 KB |
Output is correct |
15 |
Correct |
403 ms |
9556 KB |
Output is correct |
16 |
Correct |
290 ms |
6716 KB |
Output is correct |
17 |
Correct |
369 ms |
9844 KB |
Output is correct |
18 |
Correct |
355 ms |
9264 KB |
Output is correct |
19 |
Correct |
685 ms |
15920 KB |
Output is correct |
20 |
Correct |
1016 ms |
6044 KB |
Output is correct |
21 |
Correct |
207 ms |
1056 KB |
Output is correct |
22 |
Correct |
1199 ms |
8624 KB |
Output is correct |
23 |
Correct |
148 ms |
18364 KB |
Output is correct |
24 |
Correct |
563 ms |
11420 KB |
Output is correct |
25 |
Correct |
1006 ms |
18452 KB |
Output is correct |
26 |
Correct |
843 ms |
18764 KB |
Output is correct |
27 |
Correct |
784 ms |
18004 KB |
Output is correct |
28 |
Correct |
766 ms |
251888 KB |
Output is correct |
29 |
Runtime error |
1325 ms |
256000 KB |
Execution killed with signal 9 |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
423 ms |
12708 KB |
Output is correct |
13 |
Correct |
278 ms |
12876 KB |
Output is correct |
14 |
Correct |
322 ms |
9836 KB |
Output is correct |
15 |
Correct |
371 ms |
9668 KB |
Output is correct |
16 |
Correct |
252 ms |
6600 KB |
Output is correct |
17 |
Correct |
381 ms |
10020 KB |
Output is correct |
18 |
Correct |
323 ms |
9284 KB |
Output is correct |
19 |
Correct |
677 ms |
15908 KB |
Output is correct |
20 |
Correct |
1060 ms |
6040 KB |
Output is correct |
21 |
Correct |
205 ms |
840 KB |
Output is correct |
22 |
Correct |
1224 ms |
8612 KB |
Output is correct |
23 |
Correct |
172 ms |
18260 KB |
Output is correct |
24 |
Correct |
583 ms |
11428 KB |
Output is correct |
25 |
Correct |
996 ms |
18496 KB |
Output is correct |
26 |
Correct |
813 ms |
18864 KB |
Output is correct |
27 |
Correct |
757 ms |
18124 KB |
Output is correct |
28 |
Correct |
796 ms |
251732 KB |
Output is correct |
29 |
Runtime error |
1292 ms |
256000 KB |
Execution killed with signal 9 |
30 |
Halted |
0 ms |
0 KB |
- |