# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
306870 |
2020-09-26T12:28:29 Z |
sofapuden |
Game (IOI13_game) |
C++14 |
|
13000 ms |
143272 KB |
#include "game.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll gcd2(ll X, ll Y) {
ll tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
struct tree;
tree *newTree();
struct tree {
ll lb, rb, ub, db, val;
tree *ul, *ur, *bl, *br;
tree () : ul(NULL), ur(NULL), bl(NULL), br(NULL), val(0) {}
inline void initx(ll l, ll r, ll u, ll d){
lb = l, rb = r, ub = u, db = d;
}
inline void extend(){
if(!ul){
ll mid1 = (lb+rb)>>1;
ll mid2 = (ub+db)>>1;
ul = newTree();
ur = newTree();
bl = newTree();
br = newTree();
ul->initx(lb,mid1,ub,mid2);
ur->initx(mid1+(lb == rb ? 0 : 1),rb,ub,mid2);
bl->initx(lb,mid1,mid2+(ub == db ? 0 : 1),db);
br->initx(mid1+(lb == rb ? 0 : 1),rb,mid2+(ub == db ? 0 : 1),db);
}
}
ll getGCD(ll l, ll r, ll u, ll d){
if(r < lb || rb < l || d < ub || db < u){
return 0;
}
if(l <= lb && rb <= r && u <= ub && db <= d){
return val;
}
extend();
return gcd2(gcd2(ul->getGCD(l,r,u,d),ur->getGCD(l,r,u,d)),gcd2(bl->getGCD(l,r,u,d),br->getGCD(l,r,u,d)));
}
void chan(ll p1, ll p2, ll ne){
if(lb == rb && ub == db){
val = ne;
return;
}
extend();
if(p1 <= ul->rb && p2 <= ul->db)ul->chan(p1,p2,ne);
else if(p1 <= ul->rb)bl->chan(p1,p2,ne);
else if(p2 <= ul->db)ur->chan(p1,p2,ne);
else br->chan(p1,p2,ne);
val = gcd2(gcd2(ul->val,ur->val),gcd2(bl->val,br->val));
return;
}
};
tree *newTree() {
static int bufSize = 1e6;
static tree buf[(int) 1e6];
assert(bufSize);
return &buf[--bufSize];
}
tree *root = newTree();
void init(int R, int C) {
root->initx(0,C+4,0,R+4);
}
void update(int P, int Q, long long K) {
root->chan(Q,P,K);
}
long long calculate(int P, int Q, int U, int V) {
return root->getGCD(Q,V,P,U);
}
Compilation message
game.cpp: In constructor 'tree::tree()':
game.cpp:22:23: warning: 'tree::br' will be initialized after [-Wreorder]
22 | tree *ul, *ur, *bl, *br;
| ^~
game.cpp:21:21: warning: 'll tree::val' [-Wreorder]
21 | ll lb, rb, ub, db, val;
| ^~~
game.cpp:24:2: warning: when initialized here [-Wreorder]
24 | tree () : ul(NULL), ur(NULL), bl(NULL), br(NULL), val(0) {}
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
70776 KB |
Output is correct |
2 |
Correct |
41 ms |
70776 KB |
Output is correct |
3 |
Correct |
40 ms |
70784 KB |
Output is correct |
4 |
Correct |
41 ms |
70756 KB |
Output is correct |
5 |
Correct |
40 ms |
70776 KB |
Output is correct |
6 |
Correct |
39 ms |
70720 KB |
Output is correct |
7 |
Correct |
40 ms |
70776 KB |
Output is correct |
8 |
Correct |
41 ms |
70776 KB |
Output is correct |
9 |
Correct |
40 ms |
70780 KB |
Output is correct |
10 |
Correct |
41 ms |
70776 KB |
Output is correct |
11 |
Correct |
41 ms |
70776 KB |
Output is correct |
12 |
Correct |
39 ms |
70776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
70780 KB |
Output is correct |
2 |
Correct |
39 ms |
70944 KB |
Output is correct |
3 |
Correct |
40 ms |
70776 KB |
Output is correct |
4 |
Runtime error |
150 ms |
143272 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
70776 KB |
Output is correct |
2 |
Correct |
41 ms |
70776 KB |
Output is correct |
3 |
Correct |
40 ms |
70776 KB |
Output is correct |
4 |
Correct |
40 ms |
70776 KB |
Output is correct |
5 |
Correct |
41 ms |
70776 KB |
Output is correct |
6 |
Correct |
40 ms |
70776 KB |
Output is correct |
7 |
Correct |
41 ms |
70904 KB |
Output is correct |
8 |
Correct |
40 ms |
70780 KB |
Output is correct |
9 |
Correct |
40 ms |
70776 KB |
Output is correct |
10 |
Correct |
40 ms |
70776 KB |
Output is correct |
11 |
Correct |
39 ms |
70776 KB |
Output is correct |
12 |
Execution timed out |
13032 ms |
72272 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
70776 KB |
Output is correct |
2 |
Correct |
40 ms |
70776 KB |
Output is correct |
3 |
Correct |
40 ms |
70776 KB |
Output is correct |
4 |
Correct |
40 ms |
70776 KB |
Output is correct |
5 |
Correct |
40 ms |
70776 KB |
Output is correct |
6 |
Correct |
40 ms |
70776 KB |
Output is correct |
7 |
Correct |
40 ms |
70776 KB |
Output is correct |
8 |
Correct |
39 ms |
70776 KB |
Output is correct |
9 |
Correct |
41 ms |
70776 KB |
Output is correct |
10 |
Correct |
39 ms |
70784 KB |
Output is correct |
11 |
Correct |
41 ms |
70776 KB |
Output is correct |
12 |
Runtime error |
151 ms |
143224 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
70784 KB |
Output is correct |
2 |
Correct |
42 ms |
70776 KB |
Output is correct |
3 |
Correct |
40 ms |
70784 KB |
Output is correct |
4 |
Correct |
40 ms |
70776 KB |
Output is correct |
5 |
Correct |
40 ms |
70776 KB |
Output is correct |
6 |
Correct |
40 ms |
70776 KB |
Output is correct |
7 |
Correct |
40 ms |
70776 KB |
Output is correct |
8 |
Correct |
40 ms |
70776 KB |
Output is correct |
9 |
Correct |
40 ms |
70784 KB |
Output is correct |
10 |
Correct |
40 ms |
70776 KB |
Output is correct |
11 |
Correct |
40 ms |
70776 KB |
Output is correct |
12 |
Runtime error |
151 ms |
143224 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
13 |
Halted |
0 ms |
0 KB |
- |