# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1012964 |
2024-07-03T03:05:04 Z |
pcc |
게임 (IOI13_game) |
C++17 |
|
751 ms |
150612 KB |
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
inline 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;
}
int R,C;
const int mxn = 3e4+10;
const int LEN1 = 4e6+10;
const int LEN2 = mxn*30;
struct SEG2D{
struct node{
ll val;
int pl,pr;
node(){
val = pl = pr = 0;
}
};
struct node2d{
int val;
int pl,pr;
node2d(){
val = pl = pr = 0;
}
};
node seg[LEN1];
node2d seg2[LEN2];
int ptr = 0,ptr2 = 0;
SEG2D(){}
int newnode(){
ptr++;
assert(ptr<LEN1);
return ptr;
}
int newnode2(){
ptr2++;
assert(ptr2<LEN2);
return ptr2;
}
int modify(int now,int l,int r,int p,ll v,int pul,int pur){
if(!now)now = newnode();
if(l == r){
if(v >= 0)seg[now].val = v;
else seg[now].val = gcd2(seg[pul].val,seg[pur].val);
return now;
}
int mid = (l+r)>>1;
if(mid>=p)seg[now].pl = modify(seg[now].pl,l,mid,p,v,seg[pul].pl,seg[pur].pl);
else seg[now].pr = modify(seg[now].pr,mid+1,r,p,v,seg[pul].pr,seg[pur].pr);
int ls = seg[now].pl,rs = seg[now].pr;
seg[now].val = gcd2(seg[ls].val,seg[rs].val);
return now;
}
ll getval(int now,int l,int r,int s,int e){
if(!now)return 0ll;
if(l>=s&&e>=r)return seg[now].val;
int mid = (l+r)>>1;
if(mid>=e)return getval(seg[now].pl,l,mid,s,e);
else if(mid<s)return getval(seg[now].pr,mid+1,r,s,e);
else return gcd2(getval(seg[now].pl,l,mid,s,e),getval(seg[now].pr,mid+1,r,s,e));
}
int modify2(int now,int l,int r,int row,int col,ll v){
if(!now)now = newnode2();
if(l == r){
seg2[now].val = modify(seg2[now].val,0,C,col,v,0,0);
//cerr<<"SEG2D:"<<' '<<l<<' '<<r<<' '<<seg[seg2[now].val].val<<endl;
return now;
}
int mid = (l+r)>>1;
if(mid>=row)seg2[now].pl = modify2(seg2[now].pl,l,mid,row,col,v);
else seg2[now].pr = modify2(seg2[now].pr,mid+1,r,row,col,v);
seg2[now].val = modify(seg2[now].val,0,C,col,-1,seg2[seg2[now].pl].val,seg2[seg2[now].pr].val);
//cerr<<"SEG2D:"<<' '<<l<<' '<<r<<' '<<seg[seg2[now].val].val<<endl;
return now;
}
ll getval2(int now,int l,int r,int sr,int sc,int er,int ec){
if(!now)return 0ll;
if(l>=sr&&er>=r){
//cerr<<"GETVAL: "<<l<<' '<<r<<' '<<getval(seg2[now].val,0,C,sc,ec)<<endl;
return getval(seg2[now].val,0,C,sc,ec);
}
int mid = (l+r)>>1;
if(mid>=er)return getval2(seg2[now].pl,l,mid,sr,sc,er,ec);
else if(mid<sr)return getval2(seg2[now].pr,mid+1,r,sr,sc,er,ec);
else return gcd2(getval2(seg2[now].pl,l,mid,sr,sc,er,ec),getval2(seg2[now].pr,mid+1,r,sr,sc,er,ec));
}
};
SEG2D seg;
int rt;
void init(int RR, int CC) {
R = RR,C = CC;
//cerr<<"INIT!"<<" "<<R<<' '<<C<<endl;
rt = seg.newnode2();
//cerr<<"INIT!"<<endl;
}
void update(int P, int Q, long long K) {
//cerr<<"UPDATE: "<<P<<' '<<Q<<' '<<K<<endl;
rt = seg.modify2(rt,0,R,P,Q,K);
//cerr<<"UPDATE DONE!"<<endl;
}
long long calculate(int P, int Q, int U, int V) {
//cerr<<"CALC: "<<P<<' '<<Q<<' '<<U<<' '<<V<<endl;
return seg.getval2(rt,0,R,P,Q,U,V);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
73492 KB |
Output is correct |
2 |
Correct |
25 ms |
73556 KB |
Output is correct |
3 |
Correct |
25 ms |
73560 KB |
Output is correct |
4 |
Correct |
32 ms |
73556 KB |
Output is correct |
5 |
Correct |
27 ms |
73564 KB |
Output is correct |
6 |
Correct |
25 ms |
73512 KB |
Output is correct |
7 |
Correct |
25 ms |
73564 KB |
Output is correct |
8 |
Correct |
24 ms |
73440 KB |
Output is correct |
9 |
Correct |
25 ms |
73564 KB |
Output is correct |
10 |
Correct |
26 ms |
73560 KB |
Output is correct |
11 |
Correct |
25 ms |
73564 KB |
Output is correct |
12 |
Correct |
25 ms |
73564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
73564 KB |
Output is correct |
2 |
Correct |
24 ms |
73580 KB |
Output is correct |
3 |
Correct |
25 ms |
73572 KB |
Output is correct |
4 |
Correct |
250 ms |
77648 KB |
Output is correct |
5 |
Correct |
213 ms |
77748 KB |
Output is correct |
6 |
Correct |
253 ms |
74628 KB |
Output is correct |
7 |
Correct |
280 ms |
74256 KB |
Output is correct |
8 |
Correct |
202 ms |
75224 KB |
Output is correct |
9 |
Correct |
279 ms |
74320 KB |
Output is correct |
10 |
Correct |
220 ms |
73912 KB |
Output is correct |
11 |
Correct |
25 ms |
73440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
73564 KB |
Output is correct |
2 |
Correct |
26 ms |
73560 KB |
Output is correct |
3 |
Correct |
26 ms |
73480 KB |
Output is correct |
4 |
Correct |
27 ms |
73520 KB |
Output is correct |
5 |
Correct |
25 ms |
73564 KB |
Output is correct |
6 |
Correct |
27 ms |
73564 KB |
Output is correct |
7 |
Correct |
27 ms |
73560 KB |
Output is correct |
8 |
Correct |
25 ms |
73560 KB |
Output is correct |
9 |
Correct |
26 ms |
73564 KB |
Output is correct |
10 |
Correct |
26 ms |
73556 KB |
Output is correct |
11 |
Correct |
25 ms |
73564 KB |
Output is correct |
12 |
Correct |
391 ms |
77492 KB |
Output is correct |
13 |
Correct |
684 ms |
74132 KB |
Output is correct |
14 |
Correct |
170 ms |
74072 KB |
Output is correct |
15 |
Correct |
751 ms |
74312 KB |
Output is correct |
16 |
Correct |
268 ms |
74320 KB |
Output is correct |
17 |
Correct |
419 ms |
74836 KB |
Output is correct |
18 |
Correct |
592 ms |
74580 KB |
Output is correct |
19 |
Correct |
524 ms |
74576 KB |
Output is correct |
20 |
Correct |
519 ms |
74064 KB |
Output is correct |
21 |
Correct |
27 ms |
73396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
73556 KB |
Output is correct |
2 |
Correct |
29 ms |
73548 KB |
Output is correct |
3 |
Correct |
25 ms |
73552 KB |
Output is correct |
4 |
Correct |
27 ms |
73564 KB |
Output is correct |
5 |
Correct |
25 ms |
73528 KB |
Output is correct |
6 |
Correct |
25 ms |
73464 KB |
Output is correct |
7 |
Correct |
26 ms |
73560 KB |
Output is correct |
8 |
Correct |
37 ms |
73552 KB |
Output is correct |
9 |
Correct |
29 ms |
73556 KB |
Output is correct |
10 |
Correct |
25 ms |
73564 KB |
Output is correct |
11 |
Correct |
28 ms |
73508 KB |
Output is correct |
12 |
Correct |
275 ms |
77592 KB |
Output is correct |
13 |
Correct |
201 ms |
77940 KB |
Output is correct |
14 |
Correct |
272 ms |
74620 KB |
Output is correct |
15 |
Correct |
297 ms |
74320 KB |
Output is correct |
16 |
Correct |
203 ms |
75088 KB |
Output is correct |
17 |
Correct |
264 ms |
74324 KB |
Output is correct |
18 |
Correct |
289 ms |
74000 KB |
Output is correct |
19 |
Correct |
414 ms |
77652 KB |
Output is correct |
20 |
Correct |
693 ms |
74200 KB |
Output is correct |
21 |
Correct |
171 ms |
74128 KB |
Output is correct |
22 |
Correct |
728 ms |
74320 KB |
Output is correct |
23 |
Correct |
273 ms |
74112 KB |
Output is correct |
24 |
Correct |
360 ms |
74832 KB |
Output is correct |
25 |
Correct |
523 ms |
74436 KB |
Output is correct |
26 |
Correct |
511 ms |
74936 KB |
Output is correct |
27 |
Correct |
498 ms |
74068 KB |
Output is correct |
28 |
Runtime error |
181 ms |
150464 KB |
Execution killed with signal 6 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
73560 KB |
Output is correct |
2 |
Correct |
26 ms |
73556 KB |
Output is correct |
3 |
Correct |
25 ms |
73620 KB |
Output is correct |
4 |
Correct |
26 ms |
73560 KB |
Output is correct |
5 |
Correct |
27 ms |
73424 KB |
Output is correct |
6 |
Correct |
30 ms |
73552 KB |
Output is correct |
7 |
Correct |
30 ms |
73552 KB |
Output is correct |
8 |
Correct |
27 ms |
73552 KB |
Output is correct |
9 |
Correct |
26 ms |
73560 KB |
Output is correct |
10 |
Correct |
27 ms |
73564 KB |
Output is correct |
11 |
Correct |
24 ms |
73632 KB |
Output is correct |
12 |
Correct |
233 ms |
77652 KB |
Output is correct |
13 |
Correct |
228 ms |
77796 KB |
Output is correct |
14 |
Correct |
246 ms |
74624 KB |
Output is correct |
15 |
Correct |
251 ms |
74308 KB |
Output is correct |
16 |
Correct |
194 ms |
75092 KB |
Output is correct |
17 |
Correct |
263 ms |
74324 KB |
Output is correct |
18 |
Correct |
231 ms |
74064 KB |
Output is correct |
19 |
Correct |
381 ms |
77648 KB |
Output is correct |
20 |
Correct |
673 ms |
74320 KB |
Output is correct |
21 |
Correct |
163 ms |
74120 KB |
Output is correct |
22 |
Correct |
733 ms |
74136 KB |
Output is correct |
23 |
Correct |
303 ms |
74320 KB |
Output is correct |
24 |
Correct |
360 ms |
74836 KB |
Output is correct |
25 |
Correct |
539 ms |
74476 KB |
Output is correct |
26 |
Correct |
464 ms |
74660 KB |
Output is correct |
27 |
Correct |
462 ms |
74064 KB |
Output is correct |
28 |
Runtime error |
172 ms |
150612 KB |
Execution killed with signal 6 |
29 |
Halted |
0 ms |
0 KB |
- |