# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1030027 |
2024-07-21T16:33:08 Z |
tolbi |
Game (IOI13_game) |
C++17 |
|
13000 ms |
9428 KB |
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long gcd2(long long X, long long Y) {
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
mt19937_64 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
struct Treap{
struct Node{
Node *lnode, *rnode;
ll val, gg, h;
int pos;
Node(int pos, ll x):val(x),gg(x),h(ayahya()),pos(pos),lnode(nullptr),rnode(nullptr){}
} *root;
Treap():root(nullptr){}
void upd(Node* nd){
nd->gg=nd->val;
if (nd->lnode) nd->gg=gcd2(nd->lnode->gg,nd->gg);
if (nd->rnode) nd->gg=gcd2(nd->rnode->gg,nd->gg);
}
Node* merge(Node* a, Node* b){
if (!a || !b) return (a?a:b);
if (a->h > b->h) return a->rnode = merge(a->rnode,b),upd(a),a;
return b->lnode = merge(a,b->lnode),upd(b),b;
}
pair<Node*, Node*> split(Node* node, int x){
if (!node) return {nullptr,nullptr};
if (node->pos>=x){
pair<Node*, Node*> spl = split(node->lnode,x);
node->lnode=spl.second;
upd(node);
return {spl.first,node};
}
pair<Node*, Node*> spl = split(node->rnode,x);
node->rnode=spl.first;
upd(node);
return {node,spl.second};
}
void update(int x, ll val){
if (root==nullptr){
return root = new Node(x,val), void(23);
}
Node* nd = root;
while (nd){
if (nd->pos==x) break;
if (nd->pos>x) nd=nd->lnode;
else nd=nd->rnode;
}
if (nd==nullptr){
Node* nnode = new Node(x,val);
pair<Node*, Node*> spl = split(root,x);
root=merge(spl.first,nnode);
root=merge(root,spl.second);
}
else {
vector<Node*> backtrack;
nd->val=val;
upd(nd);
nd = root;
while (nd->pos!=x){
backtrack.push_back(nd);
if (nd->pos>x) nd=nd->lnode;
else nd=nd->rnode;
}
while (backtrack.size()){
upd(backtrack.back());
backtrack.pop_back();
}
}
}
ll query(int l, int r){
pair<Node*, Node*> spl = split(root, l);
pair<Node*, Node*> spl2 = split(spl.second, r+1);
ll ret = 0;
if (spl2.first) ret = spl2.first->gg;
root = merge(spl2.first,spl2.second);
root = merge(spl.first,root);
return ret;
}
};
vector<Treap> trip;
void init(int R, int C) {
/* ... */
//DO LITERALLY NOTHIN
trip.resize(R);
}
void update(int P, int Q, long long K) {
/* ... */
trip[P].update(Q,K);
}
long long calculate(int P, int Q, int U, int V) {
ll ret = 0;
for (int i = P; i <= U; i++){
ret=gcd2(ret,trip[i].query(Q,V));
}
return ret;
}
Compilation message
game.cpp: In constructor 'Treap::Node::Node(int, ll)':
game.cpp:19:7: warning: 'Treap::Node::pos' will be initialized after [-Wreorder]
19 | int pos;
| ^~~
game.cpp:17:9: warning: 'Treap::Node* Treap::Node::lnode' [-Wreorder]
17 | Node *lnode, *rnode;
| ^~~~~
game.cpp:20:3: warning: when initialized here [-Wreorder]
20 | Node(int pos, ll x):val(x),gg(x),h(ayahya()),pos(pos),lnode(nullptr),rnode(nullptr){}
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
424 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
0 ms |
440 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
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 |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
619 ms |
9428 KB |
Output is correct |
5 |
Correct |
208 ms |
9308 KB |
Output is correct |
6 |
Correct |
1121 ms |
6736 KB |
Output is correct |
7 |
Correct |
1431 ms |
6440 KB |
Output is correct |
8 |
Correct |
879 ms |
6500 KB |
Output is correct |
9 |
Correct |
1375 ms |
6420 KB |
Output is correct |
10 |
Correct |
1155 ms |
6020 KB |
Output is correct |
11 |
Correct |
1 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 |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
436 KB |
Output is correct |
8 |
Correct |
1 ms |
436 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
436 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
6839 ms |
8984 KB |
Output is correct |
13 |
Execution timed out |
13037 ms |
5004 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
1 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 |
436 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
436 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
630 ms |
9300 KB |
Output is correct |
13 |
Correct |
202 ms |
9296 KB |
Output is correct |
14 |
Correct |
1139 ms |
6776 KB |
Output is correct |
15 |
Correct |
1360 ms |
6284 KB |
Output is correct |
16 |
Correct |
841 ms |
6568 KB |
Output is correct |
17 |
Correct |
1258 ms |
6568 KB |
Output is correct |
18 |
Correct |
1093 ms |
5972 KB |
Output is correct |
19 |
Correct |
6660 ms |
9396 KB |
Output is correct |
20 |
Execution timed out |
13012 ms |
4828 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 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 |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
619 ms |
9276 KB |
Output is correct |
13 |
Correct |
208 ms |
9288 KB |
Output is correct |
14 |
Correct |
1134 ms |
6724 KB |
Output is correct |
15 |
Correct |
1355 ms |
6416 KB |
Output is correct |
16 |
Correct |
897 ms |
6484 KB |
Output is correct |
17 |
Correct |
1343 ms |
6532 KB |
Output is correct |
18 |
Correct |
1195 ms |
5972 KB |
Output is correct |
19 |
Correct |
6851 ms |
9228 KB |
Output is correct |
20 |
Execution timed out |
13034 ms |
4844 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |