# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1087609 |
2024-09-13T02:41:32 Z |
Zero_OP |
Game (IOI13_game) |
C++17 |
|
2839 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 = 1e7 + 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 |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 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 |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
296 ms |
8508 KB |
Output is correct |
5 |
Correct |
260 ms |
9132 KB |
Output is correct |
6 |
Correct |
277 ms |
5656 KB |
Output is correct |
7 |
Correct |
293 ms |
5456 KB |
Output is correct |
8 |
Correct |
197 ms |
4348 KB |
Output is correct |
9 |
Correct |
306 ms |
5460 KB |
Output is correct |
10 |
Correct |
254 ms |
5048 KB |
Output is correct |
11 |
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 |
1 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 |
1 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 |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
504 ms |
10768 KB |
Output is correct |
13 |
Correct |
741 ms |
4176 KB |
Output is correct |
14 |
Correct |
180 ms |
868 KB |
Output is correct |
15 |
Correct |
901 ms |
5884 KB |
Output is correct |
16 |
Correct |
100 ms |
11344 KB |
Output is correct |
17 |
Correct |
495 ms |
7712 KB |
Output is correct |
18 |
Correct |
744 ms |
11600 KB |
Output is correct |
19 |
Correct |
649 ms |
11712 KB |
Output is correct |
20 |
Correct |
636 ms |
11144 KB |
Output is correct |
21 |
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 |
344 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 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 |
318 ms |
8420 KB |
Output is correct |
13 |
Correct |
193 ms |
8788 KB |
Output is correct |
14 |
Correct |
272 ms |
5712 KB |
Output is correct |
15 |
Correct |
315 ms |
5460 KB |
Output is correct |
16 |
Correct |
203 ms |
4432 KB |
Output is correct |
17 |
Correct |
290 ms |
5464 KB |
Output is correct |
18 |
Correct |
245 ms |
5204 KB |
Output is correct |
19 |
Correct |
464 ms |
10836 KB |
Output is correct |
20 |
Correct |
753 ms |
4160 KB |
Output is correct |
21 |
Correct |
164 ms |
1052 KB |
Output is correct |
22 |
Correct |
902 ms |
5944 KB |
Output is correct |
23 |
Correct |
112 ms |
11300 KB |
Output is correct |
24 |
Correct |
484 ms |
7760 KB |
Output is correct |
25 |
Correct |
752 ms |
11600 KB |
Output is correct |
26 |
Correct |
648 ms |
11860 KB |
Output is correct |
27 |
Correct |
617 ms |
11108 KB |
Output is correct |
28 |
Correct |
436 ms |
157528 KB |
Output is correct |
29 |
Correct |
1182 ms |
185768 KB |
Output is correct |
30 |
Correct |
2839 ms |
126544 KB |
Output is correct |
31 |
Correct |
2730 ms |
98300 KB |
Output is correct |
32 |
Correct |
318 ms |
10280 KB |
Output is correct |
33 |
Correct |
402 ms |
11952 KB |
Output is correct |
34 |
Correct |
274 ms |
179540 KB |
Output is correct |
35 |
Correct |
826 ms |
97616 KB |
Output is correct |
36 |
Correct |
1525 ms |
183636 KB |
Output is correct |
37 |
Correct |
1276 ms |
183888 KB |
Output is correct |
38 |
Correct |
1353 ms |
183376 KB |
Output is correct |
39 |
Correct |
1053 ms |
143320 KB |
Output is correct |
40 |
Correct |
0 ms |
344 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 |
1 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 |
1 ms |
344 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 |
348 KB |
Output is correct |
12 |
Correct |
286 ms |
8560 KB |
Output is correct |
13 |
Correct |
189 ms |
8800 KB |
Output is correct |
14 |
Correct |
259 ms |
5660 KB |
Output is correct |
15 |
Correct |
297 ms |
5460 KB |
Output is correct |
16 |
Correct |
199 ms |
4348 KB |
Output is correct |
17 |
Correct |
291 ms |
5560 KB |
Output is correct |
18 |
Correct |
250 ms |
5024 KB |
Output is correct |
19 |
Correct |
520 ms |
10832 KB |
Output is correct |
20 |
Correct |
813 ms |
4292 KB |
Output is correct |
21 |
Correct |
161 ms |
1160 KB |
Output is correct |
22 |
Correct |
865 ms |
5888 KB |
Output is correct |
23 |
Correct |
101 ms |
11344 KB |
Output is correct |
24 |
Correct |
490 ms |
7772 KB |
Output is correct |
25 |
Correct |
769 ms |
11600 KB |
Output is correct |
26 |
Correct |
681 ms |
11764 KB |
Output is correct |
27 |
Correct |
609 ms |
11088 KB |
Output is correct |
28 |
Correct |
431 ms |
157524 KB |
Output is correct |
29 |
Correct |
1232 ms |
185780 KB |
Output is correct |
30 |
Correct |
2804 ms |
126636 KB |
Output is correct |
31 |
Correct |
2592 ms |
98392 KB |
Output is correct |
32 |
Correct |
301 ms |
10428 KB |
Output is correct |
33 |
Correct |
397 ms |
11860 KB |
Output is correct |
34 |
Correct |
285 ms |
179576 KB |
Output is correct |
35 |
Correct |
850 ms |
97696 KB |
Output is correct |
36 |
Correct |
1616 ms |
183712 KB |
Output is correct |
37 |
Correct |
1272 ms |
183928 KB |
Output is correct |
38 |
Correct |
1266 ms |
183376 KB |
Output is correct |
39 |
Runtime error |
2510 ms |
256000 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |