# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1087610 |
2024-09-13T02:43:02 Z |
Zero_OP |
Game (IOI13_game) |
C++14 |
|
2771 ms |
256000 KB |
#ifndef LOCAL
#include "game.h"
#endif //LOCAL
#include <bits/stdc++.h>
using namespace std;
#define sz(v) (int)v.size()
#define all(v) begin(v), end(v)
#define compact(v) v.erase(unique(all(v)), end(v))
#define dbg(x) "[" #x " = " << (x) << "]"
template<typename T>
bool minimize(T& a, const T& b){
if(a > b) return a = b, true;
return false;
}
template<typename T>
bool maximize(T& a, const T& b){
if(a < b) return a = b, true;
return false;
}
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
long long gcd2(long long X, long long Y) {
// cout << X << ' ' << Y << '\n';
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
const int MAX = 2e7 + 5;
int N, M, tree2D, lt[MAX], rt[MAX], id[MAX], num;
long long st[MAX];
void define(int& x){
if(x == 0) x = ++num;
}
void update_y(int& idx, int lx, int rx, int tl, int tr, int& idy, int ly, int ry, int y, long long k){
define(idy);
if(ly == ry){
if(lx == rx) st[idy] = k;
else st[idy] = gcd2(st[tl], st[tr]);
} else{
int mid = (ly + ry) >> 1;
if(y <= mid) update_y(idx, lx, rx, lt[tl], lt[tr], lt[idy], ly, mid, y, k);
else update_y(idx, lx, rx, rt[tl], rt[tr], rt[idy], mid + 1, ry, y, k);
st[idy] = gcd2(st[lt[idy]], st[rt[idy]]);
}
}
void update_x(int& idx, int lx, int rx, int x, int y, long long k){
define(idx);
if(lx < rx){
int mid = lx + rx >> 1;
if(x <= mid) update_x(lt[idx], lx, mid, x, y, k);
else update_x(rt[idx], mid + 1, rx, x, y, k);
}
update_y(idx, lx, rx, id[lt[idx]], id[rt[idx]], id[idx], 0, M - 1, y, k);
}
long long query_y(int& idy, int ly, int ry, int u, int v){
if((u <= ly && ry <= v) || idy == 0) return st[idy];
int mid = ly + ry >> 1;
long long g = 0;
if(u <= mid) g = gcd2(g, query_y(lt[idy], ly, mid, u, v));
if(mid < v) g = gcd2(g, query_y(rt[idy], mid + 1, ry, u, v));
return g;
}
long long query_x(int& idx, int lx, int rx, int u, int v, int p, int q){
if((u <= lx && rx <= v) || idx == 0) return query_y(id[idx], 0, M - 1, p, q);
int mid = lx + rx >> 1;
long long g = 0;
if(u <= mid) g = gcd2(g, query_x(lt[idx], lx, mid, u, v, p, q));
if(mid < v) g = gcd2(g, query_x(rt[idx], mid + 1, rx, u, v, p, q));
return g;
}
void init(int R, int C) {
N = R;
M = C;
}
void update(int P, int Q, long long K) {
update_x(tree2D, 0, N - 1, P, Q, K);
}
long long calculate(int P, int Q, int U, int V) {
return query_x(tree2D, 0, N - 1, P, U, Q, V);
}
#ifdef LOCAL
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#define filename "task"
if(fopen(filename".inp", "r")){
freopen(filename".inp", "r", stdin);
freopen(filename".out", "w", stdout);
}
int Q;
cin >> N >> M >> Q;
init(N, M);
while(Q--){
int type;
cin >> type;
if(type == 1){
int x, y; long long z;
cin >> x >> y >> z;
update(x, y, z);
} else{
int p, q, u, v;
cin >> p >> q >> u >> v;
cout << calculate(p, q, u, v) << '\n';
}
}
return 0;
}
#endif // LOCAL
Compilation message
game.cpp: In function 'void update_x(int&, int, int, int, int, long long int)':
game.cpp:70:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
70 | int mid = lx + rx >> 1;
| ~~~^~~~
game.cpp: In function 'long long int query_y(int&, int, int, int, int)':
game.cpp:80:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
80 | int mid = ly + ry >> 1;
| ~~~^~~~
game.cpp: In function 'long long int query_x(int&, int, int, int, int, int, int)':
game.cpp:89:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
89 | int mid = lx + rx >> 1;
| ~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
600 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 |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
291 ms |
8644 KB |
Output is correct |
5 |
Correct |
197 ms |
8784 KB |
Output is correct |
6 |
Correct |
264 ms |
5712 KB |
Output is correct |
7 |
Correct |
287 ms |
5456 KB |
Output is correct |
8 |
Correct |
207 ms |
4432 KB |
Output is correct |
9 |
Correct |
290 ms |
5456 KB |
Output is correct |
10 |
Correct |
293 ms |
5008 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 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 |
344 KB |
Output is correct |
9 |
Correct |
0 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 |
471 ms |
10832 KB |
Output is correct |
13 |
Correct |
759 ms |
4224 KB |
Output is correct |
14 |
Correct |
174 ms |
936 KB |
Output is correct |
15 |
Correct |
886 ms |
5968 KB |
Output is correct |
16 |
Correct |
108 ms |
11348 KB |
Output is correct |
17 |
Correct |
486 ms |
7944 KB |
Output is correct |
18 |
Correct |
757 ms |
11868 KB |
Output is correct |
19 |
Correct |
648 ms |
11856 KB |
Output is correct |
20 |
Correct |
610 ms |
11228 KB |
Output is correct |
21 |
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 |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
308 ms |
8456 KB |
Output is correct |
13 |
Correct |
229 ms |
9036 KB |
Output is correct |
14 |
Correct |
265 ms |
5712 KB |
Output is correct |
15 |
Correct |
311 ms |
5384 KB |
Output is correct |
16 |
Correct |
196 ms |
4232 KB |
Output is correct |
17 |
Correct |
290 ms |
5460 KB |
Output is correct |
18 |
Correct |
254 ms |
4996 KB |
Output is correct |
19 |
Correct |
524 ms |
10812 KB |
Output is correct |
20 |
Correct |
761 ms |
4504 KB |
Output is correct |
21 |
Correct |
157 ms |
848 KB |
Output is correct |
22 |
Correct |
908 ms |
5952 KB |
Output is correct |
23 |
Correct |
105 ms |
11344 KB |
Output is correct |
24 |
Correct |
502 ms |
7760 KB |
Output is correct |
25 |
Correct |
759 ms |
11628 KB |
Output is correct |
26 |
Correct |
671 ms |
11860 KB |
Output is correct |
27 |
Correct |
613 ms |
11292 KB |
Output is correct |
28 |
Correct |
411 ms |
157520 KB |
Output is correct |
29 |
Correct |
1198 ms |
175676 KB |
Output is correct |
30 |
Correct |
2768 ms |
119648 KB |
Output is correct |
31 |
Correct |
2636 ms |
91472 KB |
Output is correct |
32 |
Correct |
315 ms |
1152 KB |
Output is correct |
33 |
Correct |
394 ms |
2816 KB |
Output is correct |
34 |
Correct |
275 ms |
172884 KB |
Output is correct |
35 |
Correct |
862 ms |
87888 KB |
Output is correct |
36 |
Correct |
1758 ms |
173140 KB |
Output is correct |
37 |
Correct |
1227 ms |
173240 KB |
Output is correct |
38 |
Correct |
1243 ms |
172632 KB |
Output is correct |
39 |
Correct |
1148 ms |
133204 KB |
Output is correct |
40 |
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 |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 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 |
1 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 |
379 ms |
8536 KB |
Output is correct |
13 |
Correct |
203 ms |
8820 KB |
Output is correct |
14 |
Correct |
274 ms |
5712 KB |
Output is correct |
15 |
Correct |
333 ms |
5276 KB |
Output is correct |
16 |
Correct |
198 ms |
4436 KB |
Output is correct |
17 |
Correct |
290 ms |
5584 KB |
Output is correct |
18 |
Correct |
254 ms |
5200 KB |
Output is correct |
19 |
Correct |
493 ms |
10980 KB |
Output is correct |
20 |
Correct |
749 ms |
4212 KB |
Output is correct |
21 |
Correct |
163 ms |
848 KB |
Output is correct |
22 |
Correct |
910 ms |
5744 KB |
Output is correct |
23 |
Correct |
142 ms |
11344 KB |
Output is correct |
24 |
Correct |
499 ms |
7760 KB |
Output is correct |
25 |
Correct |
818 ms |
11604 KB |
Output is correct |
26 |
Correct |
667 ms |
11696 KB |
Output is correct |
27 |
Correct |
593 ms |
11268 KB |
Output is correct |
28 |
Correct |
426 ms |
157520 KB |
Output is correct |
29 |
Correct |
1177 ms |
175700 KB |
Output is correct |
30 |
Correct |
2771 ms |
119500 KB |
Output is correct |
31 |
Correct |
2711 ms |
91480 KB |
Output is correct |
32 |
Correct |
286 ms |
1104 KB |
Output is correct |
33 |
Correct |
387 ms |
2640 KB |
Output is correct |
34 |
Correct |
312 ms |
172880 KB |
Output is correct |
35 |
Correct |
891 ms |
87956 KB |
Output is correct |
36 |
Correct |
1623 ms |
173144 KB |
Output is correct |
37 |
Correct |
1333 ms |
173336 KB |
Output is correct |
38 |
Correct |
1273 ms |
172956 KB |
Output is correct |
39 |
Runtime error |
504 ms |
256000 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |