# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
988154 |
2024-05-24T07:04:11 Z |
cig32 |
게임 (IOI13_game) |
C++17 |
|
1381 ms |
160084 KB |
#include "game.h"
#include "bits/stdc++.h"
using namespace std;
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;
}
const int MAXN = 1e5 + 10;
long long st[10][4 * MAXN];
void u(int l, int r, int row, int tar, int idx, long long val) {
if(l == r) {
st[row][idx] = val;
return;
}
int mid = (l + r) >> 1;
if(tar <= mid) u(l, mid, row, tar, (idx<<1) + 1, val);
else u(mid+1, r, row, tar, (idx<<1) + 2, val);
st[row][idx] = gcd2(st[row][(idx<<1) + 1], st[row][(idx<<1) + 2]);
}
long long qu(int l, int r, int constl, int constr, int row, int idx) {
if(l <= constl && constr <= r) return st[row][idx];
int mid = (constl + constr) >> 1;
if(mid < l || r < constl) return qu(l, r, mid+1, constr, row, (idx<<1) + 2);
else if(constr < l || r < mid+1) return qu(l, r, constl, mid, row, (idx<<1) + 1);
else {
return gcd2(qu(l, r, constl, mid, row, (idx<<1) + 1), qu(l, r, mid+1, constr, row, (idx<<1) + 2));
}
}
long long st2[8010][8010];
int r, c;
void init(int R, int C) {
r = R;
c = C;
}
void horizontal(int vl, int vr, int vtar, int vidx, int hl, int hr, int htar, int hidx, long long val) {
if(hl == hr) {
if(vl == vr) st2[vidx][hidx] = val;
else st2[vidx][hidx] = gcd2(st2[(vidx << 1) + 1][hidx], st2[(vidx << 1) + 2][hidx]);
return;
}
int mid = (hl + hr) >> 1;
if(htar <= mid) horizontal(vl, vr, vtar, vidx, hl, mid, htar, (hidx << 1) + 1, val);
else horizontal(vl, vr, vtar, vidx, mid + 1, hr, htar, (hidx << 1) + 2, val);
st2[vidx][hidx] = gcd2(st2[vidx][(hidx << 1) + 1], st2[vidx][(hidx << 1) + 2]);
}
void vertical(int vl, int vr, int vtar, int vidx, int htar, long long val) {
if(vl != vr) {
int mid = (vl + vr) >> 1;
if(vtar <= mid) vertical(vl, mid, vtar, (vidx << 1) + 1, htar, val);
else vertical(mid + 1, vr, vtar, (vidx << 1) + 2, htar, val);
}
horizontal(vl, vr, vtar, vidx, 0, c - 1, htar, 0, val);
}
long long qh(int vidx, int hl, int hr, int hconstl, int hconstr, int hidx) {
if(hl <= hconstl && hconstr <= hr) return st2[vidx][hidx];
int mid = (hconstl + hconstr) >> 1;
if(mid < hl || hr < hconstl) return qh(vidx, hl, hr, mid + 1, hconstr, (hidx << 1) + 2);
else if(hconstr < hl || hr < mid + 1) return qh(vidx, hl, hr, hconstl, mid, (hidx << 1) + 1);
else {
return gcd2(
qh(vidx, hl, hr, hconstl, mid, (hidx << 1) + 1),
qh(vidx, hl, hr, mid + 1, hconstr, (hidx << 1) + 2)
);
}
}
long long qv(int vl, int vr, int vconstl, int vconstr, int vidx, int hl, int hr) {
if(vl <= vconstl && vconstr <= vr) return qh(vidx, hl, hr, 0, c - 1, 0);
int mid = (vconstl + vconstr) >> 1;
if(mid < vl || vr < vconstl) return qv(vl, vr, mid + 1, vconstr, (vidx << 1) + 2, hl, hr);
else if(vconstr < vl || vr < mid + 1) return qv(vl, vr, vconstl, mid, (vidx << 1) + 1, hl, hr);
else {
return gcd2(qv(vl, vr, vconstl, mid, (vidx << 1) + 1, hl, hr),
qv(vl, vr, mid + 1, vconstr, (vidx << 1) + 2, hl, hr)
);
}
}
void update(int P, int Q, long long K) {
if(max(r, c) <= 2000) {
vertical(0, r - 1, P, 0, Q, K);
return;
}
u(0, c - 1, P, Q, 0, K);
}
long long calculate(int P, int Q, int U, int V) {
if(max(r, c) <= 2000) {
return qv(P, U, 0, r - 1, 0, Q, V);
}
long long ans = 0;
for(int i=P; i<=U; i++) ans = gcd2(ans, qu(Q, V, 0, c - 1, i, 0));
return ans;
}
/*
g++ -std=c++17 -O2 -o T2444 grador.cpp T2444.cpp
./T2444 < input.txt
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
16728 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
16732 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
14684 KB |
Output is correct |
10 |
Correct |
2 ms |
4952 KB |
Output is correct |
11 |
Correct |
2 ms |
12636 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
573 ms |
31024 KB |
Output is correct |
5 |
Correct |
399 ms |
30860 KB |
Output is correct |
6 |
Correct |
500 ms |
25936 KB |
Output is correct |
7 |
Correct |
526 ms |
37204 KB |
Output is correct |
8 |
Correct |
410 ms |
23908 KB |
Output is correct |
9 |
Correct |
518 ms |
25684 KB |
Output is correct |
10 |
Correct |
475 ms |
25420 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
3 ms |
16732 KB |
Output is correct |
3 |
Correct |
2 ms |
10844 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
16728 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
14776 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
659 ms |
85984 KB |
Output is correct |
13 |
Correct |
984 ms |
77504 KB |
Output is correct |
14 |
Correct |
436 ms |
61776 KB |
Output is correct |
15 |
Correct |
1165 ms |
120404 KB |
Output is correct |
16 |
Correct |
192 ms |
160084 KB |
Output is correct |
17 |
Correct |
961 ms |
115796 KB |
Output is correct |
18 |
Correct |
1234 ms |
142128 KB |
Output is correct |
19 |
Correct |
1381 ms |
139484 KB |
Output is correct |
20 |
Correct |
1221 ms |
138416 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
16732 KB |
Output is correct |
3 |
Correct |
3 ms |
10844 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
16732 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
3 ms |
14680 KB |
Output is correct |
10 |
Correct |
2 ms |
4956 KB |
Output is correct |
11 |
Correct |
3 ms |
12636 KB |
Output is correct |
12 |
Correct |
564 ms |
31092 KB |
Output is correct |
13 |
Correct |
419 ms |
31088 KB |
Output is correct |
14 |
Correct |
491 ms |
25772 KB |
Output is correct |
15 |
Correct |
502 ms |
37204 KB |
Output is correct |
16 |
Correct |
416 ms |
24108 KB |
Output is correct |
17 |
Correct |
515 ms |
25684 KB |
Output is correct |
18 |
Correct |
461 ms |
25424 KB |
Output is correct |
19 |
Correct |
664 ms |
83024 KB |
Output is correct |
20 |
Correct |
994 ms |
76112 KB |
Output is correct |
21 |
Correct |
436 ms |
57500 KB |
Output is correct |
22 |
Correct |
1175 ms |
119004 KB |
Output is correct |
23 |
Correct |
201 ms |
155072 KB |
Output is correct |
24 |
Correct |
967 ms |
115540 KB |
Output is correct |
25 |
Correct |
1232 ms |
141916 KB |
Output is correct |
26 |
Correct |
1218 ms |
139656 KB |
Output is correct |
27 |
Correct |
1165 ms |
138320 KB |
Output is correct |
28 |
Runtime error |
11 ms |
348 KB |
Execution killed with signal 11 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
16732 KB |
Output is correct |
3 |
Correct |
3 ms |
10936 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
16820 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
4 ms |
14684 KB |
Output is correct |
10 |
Correct |
1 ms |
4956 KB |
Output is correct |
11 |
Correct |
2 ms |
12728 KB |
Output is correct |
12 |
Correct |
571 ms |
31228 KB |
Output is correct |
13 |
Correct |
399 ms |
31004 KB |
Output is correct |
14 |
Correct |
490 ms |
25912 KB |
Output is correct |
15 |
Correct |
529 ms |
37716 KB |
Output is correct |
16 |
Correct |
381 ms |
23920 KB |
Output is correct |
17 |
Correct |
556 ms |
25800 KB |
Output is correct |
18 |
Correct |
515 ms |
25412 KB |
Output is correct |
19 |
Correct |
652 ms |
83040 KB |
Output is correct |
20 |
Correct |
978 ms |
76316 KB |
Output is correct |
21 |
Correct |
430 ms |
57684 KB |
Output is correct |
22 |
Correct |
1211 ms |
117656 KB |
Output is correct |
23 |
Correct |
196 ms |
156244 KB |
Output is correct |
24 |
Correct |
963 ms |
115440 KB |
Output is correct |
25 |
Correct |
1339 ms |
142228 KB |
Output is correct |
26 |
Correct |
1218 ms |
139364 KB |
Output is correct |
27 |
Correct |
1169 ms |
138404 KB |
Output is correct |
28 |
Runtime error |
10 ms |
344 KB |
Execution killed with signal 11 |
29 |
Halted |
0 ms |
0 KB |
- |