답안 #96979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
96979 2019-02-13T04:45:48 Z kig9981 게임 (IOI13_game) C++17
80 / 100
7099 ms 257024 KB
#include "game.h"
#include <bits/stdc++.h>
 
using namespace std;
 
struct Seg
{
	int l, r;
	long long v;
	Seg() : l(0), r(0), v(0) {}
};
 
const int MAX=1e9;
Seg tree[222222], tree2[14444444];
int tp1=1, tp2;
 
long long GCD(long long a, long long b)
{
	for(;b;a%=b,swap(a,b));
	return a;
}
 
long long get_gcd2(int n1, int n2, int p, int s=0, int e=MAX)
{
	int m=(s+e)>>1;
	if(p==0 || n2<s || e<n1) return 0;
    if(tree2[p].l<0) return n1<=-tree2[p].l-1 && -tree2[p].l-1<=n2 ? tree2[p].v:0;
	if(n1<=s && e<=n2) return tree2[p].v;
	return GCD(get_gcd2(n1,n2,tree2[p].l,s,m),get_gcd2(n1,n2,tree2[p].r,m+1,e));
}
 
long long get_gcd(int x1, int x2, int y1, int y2, int p=1, int s=0, int e=MAX)
{
	int m=(s+e)>>1;
	if(p==0 || x2<s || e<x1) return 0;
	if(x1<=s && e<=x2) return get_gcd2(y1,y2,tree[p].v);
	return GCD(get_gcd(x1,x2,y1,y2,tree[p].l,s,m),get_gcd(x1,x2,y1,y2,tree[p].r,m+1,e));
}
 
void set_tree2(int n, long long v, int p, int s=0, int e=MAX)
{
	int m=(s+e)>>1;
	if(s==e) {
		tree2[p].v=v;
		return;
	}
	if(tree2[p].l<0) {
        int t=-tree2[p].l-1;
		if(t==n) {
			tree2[p].v=v;
			return;
		}
        tree2[p].l=0;
		if(t<=m) {
			tree2[tree2[p].l=++tp2].l=-t-1;
			tree2[tree2[p].l].v=tree2[p].v;
        }
        else {
            tree2[tree2[p].r=++tp2].l=-t-1;
            tree2[tree2[p].r].v=tree2[p].v;
        }
    }
    if(tree2[p].l==0 && tree2[p].r==0) {
        tree2[p].v=v;
        tree2[p].l=-n-1;
        return;
    }
	if(n<=m) {
		if(tree2[p].l==0) tree2[p].l=++tp2;
		set_tree2(n,v,tree2[p].l,s,m);
	}
	else {
		if(tree2[p].r==0) tree2[p].r=++tp2;
		set_tree2(n,v,tree2[p].r,m+1,e);
	}
	tree2[p].v=GCD(tree2[tree2[p].l].v,tree2[tree2[p].r].v);
}
 
void set_tree(int x, int y, long long v, int p=1, int s=0, int e=MAX)
{
	int m=(s+e)>>1;
	if(tree[p].v==0) tree[p].v=++tp2;
	if(s==e) {
        set_tree2(y,v,tree[p].v);
        return;
    }
	if(x<=m) {
		if(tree[p].l==0) tree[p].l=++tp1;
		set_tree(x,y,v,tree[p].l,s,m);
	}
	else {
		if(tree[p].r==0) tree[p].r=++tp1;
		set_tree(x,y,v,tree[p].r,m+1,e);
	}
    set_tree2(y,GCD(get_gcd2(y,y,tree[tree[p].l].v),get_gcd2(y,y,tree[tree[p].r].v)),tree[p].v);
}
 
void init(int R, int C) {}
 
void update(int P, int Q, long long K) {set_tree(P,Q,K);}
 
long long calculate(int P, int Q, int U, int V) {return get_gcd(P,U,Q,V);}

Compilation message

grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 229880 KB Output is correct
2 Correct 189 ms 229968 KB Output is correct
3 Correct 182 ms 229880 KB Output is correct
4 Correct 199 ms 229892 KB Output is correct
5 Correct 159 ms 230136 KB Output is correct
6 Correct 163 ms 229880 KB Output is correct
7 Correct 183 ms 229880 KB Output is correct
8 Correct 185 ms 229892 KB Output is correct
9 Correct 188 ms 230052 KB Output is correct
10 Correct 184 ms 230092 KB Output is correct
11 Correct 186 ms 230008 KB Output is correct
12 Correct 188 ms 229992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 230044 KB Output is correct
2 Correct 187 ms 229880 KB Output is correct
3 Correct 182 ms 230008 KB Output is correct
4 Correct 1276 ms 234056 KB Output is correct
5 Correct 1086 ms 234232 KB Output is correct
6 Correct 1489 ms 231012 KB Output is correct
7 Correct 1735 ms 230848 KB Output is correct
8 Correct 1145 ms 231740 KB Output is correct
9 Correct 1454 ms 231028 KB Output is correct
10 Correct 1423 ms 230632 KB Output is correct
11 Correct 165 ms 229880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 230044 KB Output is correct
2 Correct 163 ms 229880 KB Output is correct
3 Correct 179 ms 230008 KB Output is correct
4 Correct 164 ms 229880 KB Output is correct
5 Correct 155 ms 230040 KB Output is correct
6 Correct 170 ms 229996 KB Output is correct
7 Correct 169 ms 230040 KB Output is correct
8 Correct 157 ms 230008 KB Output is correct
9 Correct 164 ms 229880 KB Output is correct
10 Correct 181 ms 229920 KB Output is correct
11 Correct 166 ms 229880 KB Output is correct
12 Correct 2366 ms 234156 KB Output is correct
13 Correct 3644 ms 230764 KB Output is correct
14 Correct 970 ms 230448 KB Output is correct
15 Correct 3438 ms 230848 KB Output is correct
16 Correct 1010 ms 230684 KB Output is correct
17 Correct 2013 ms 231508 KB Output is correct
18 Correct 3826 ms 231148 KB Output is correct
19 Correct 3410 ms 231208 KB Output is correct
20 Correct 2848 ms 230728 KB Output is correct
21 Correct 184 ms 230012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 229956 KB Output is correct
2 Correct 178 ms 230136 KB Output is correct
3 Correct 168 ms 229988 KB Output is correct
4 Correct 167 ms 230012 KB Output is correct
5 Correct 190 ms 229948 KB Output is correct
6 Correct 176 ms 230008 KB Output is correct
7 Correct 184 ms 229852 KB Output is correct
8 Correct 190 ms 229880 KB Output is correct
9 Correct 198 ms 230032 KB Output is correct
10 Correct 185 ms 229884 KB Output is correct
11 Correct 172 ms 229980 KB Output is correct
12 Correct 1397 ms 234104 KB Output is correct
13 Correct 1082 ms 234360 KB Output is correct
14 Correct 1410 ms 231132 KB Output is correct
15 Correct 1355 ms 230756 KB Output is correct
16 Correct 1061 ms 231628 KB Output is correct
17 Correct 1470 ms 230964 KB Output is correct
18 Correct 1612 ms 230616 KB Output is correct
19 Correct 3972 ms 233948 KB Output is correct
20 Correct 2981 ms 230628 KB Output is correct
21 Correct 1012 ms 230400 KB Output is correct
22 Correct 3490 ms 230704 KB Output is correct
23 Correct 1147 ms 230664 KB Output is correct
24 Correct 1939 ms 231416 KB Output is correct
25 Correct 3775 ms 231004 KB Output is correct
26 Correct 3030 ms 231412 KB Output is correct
27 Correct 2503 ms 230616 KB Output is correct
28 Correct 893 ms 230576 KB Output is correct
29 Correct 2110 ms 233732 KB Output is correct
30 Correct 6950 ms 230560 KB Output is correct
31 Correct 6772 ms 230820 KB Output is correct
32 Correct 997 ms 230648 KB Output is correct
33 Correct 1423 ms 230512 KB Output is correct
34 Correct 1598 ms 230744 KB Output is correct
35 Correct 1728 ms 231336 KB Output is correct
36 Correct 3531 ms 231132 KB Output is correct
37 Correct 2453 ms 231236 KB Output is correct
38 Correct 2800 ms 230668 KB Output is correct
39 Correct 2324 ms 231404 KB Output is correct
40 Correct 177 ms 230012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 229976 KB Output is correct
2 Correct 186 ms 230172 KB Output is correct
3 Correct 178 ms 229912 KB Output is correct
4 Correct 163 ms 229980 KB Output is correct
5 Correct 193 ms 229980 KB Output is correct
6 Correct 192 ms 230008 KB Output is correct
7 Correct 188 ms 229984 KB Output is correct
8 Correct 202 ms 230028 KB Output is correct
9 Correct 189 ms 230028 KB Output is correct
10 Correct 182 ms 229880 KB Output is correct
11 Correct 162 ms 229880 KB Output is correct
12 Correct 1462 ms 233984 KB Output is correct
13 Correct 1150 ms 234360 KB Output is correct
14 Correct 1583 ms 231132 KB Output is correct
15 Correct 1618 ms 231032 KB Output is correct
16 Correct 953 ms 231772 KB Output is correct
17 Correct 1704 ms 230876 KB Output is correct
18 Correct 1382 ms 230568 KB Output is correct
19 Correct 2316 ms 234076 KB Output is correct
20 Correct 3184 ms 230792 KB Output is correct
21 Correct 1022 ms 230424 KB Output is correct
22 Correct 3752 ms 230748 KB Output is correct
23 Correct 1147 ms 230780 KB Output is correct
24 Correct 2226 ms 231416 KB Output is correct
25 Correct 3832 ms 231240 KB Output is correct
26 Correct 3302 ms 231320 KB Output is correct
27 Correct 3257 ms 230788 KB Output is correct
28 Correct 987 ms 230808 KB Output is correct
29 Correct 2370 ms 233652 KB Output is correct
30 Correct 7099 ms 230612 KB Output is correct
31 Correct 6946 ms 230844 KB Output is correct
32 Correct 1071 ms 230616 KB Output is correct
33 Correct 1381 ms 230544 KB Output is correct
34 Correct 1422 ms 230788 KB Output is correct
35 Correct 1629 ms 231456 KB Output is correct
36 Correct 3103 ms 231096 KB Output is correct
37 Correct 2554 ms 231288 KB Output is correct
38 Correct 2245 ms 230720 KB Output is correct
39 Runtime error 1106 ms 257024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -