답안 #49002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49002 2018-05-21T06:33:53 Z Namnamseo 게임 (IOI13_game) C++17
100 / 100
9488 ms 256000 KB
#include "game.h"
#include <cstdio>

typedef long long ll;

#define DBG if(0)

ll gcd2(ll a,ll b){ return b?gcd2(b,a%b):a; }
/*
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;
}
*/
struct node {
	node *lp, *rp;
	ll val;
	int l,r;
	int sing_pos;
	
	node(int a,int b){
		l=a; r=b;
		lp=rp=0;
		val=0;
		sing_pos = -1;
	}

	void insert_val(int pos,ll v){
		if(l==r){
			val=v;
			return;
		}
		int mid=(l+r)/2;
		//printf("insert_val %d,%lld; mid %d\n",pos,v,mid);
		if(pos<=mid){
			if(!lp) lp=new node(l, mid);
			lp->update(pos, v);
		} else {
			if(!rp) rp=new node(mid+1, r);
			rp->update(pos, v);
		}
		val = 0;
		if(lp) val=gcd2(val, lp->val);
		if(rp) val=gcd2(val, rp->val);
		//printf("my %d~%d : %lld\n",l,r,val);
	}

	void update(int pos,ll uv){
		DBG printf(">>> %lld: i am %d~%d. small-update %d / val %lld\n",ll(this)&0xffff, l,r,pos,uv);
		if(lp==0 && rp==0){
			if(sing_pos == -1 || sing_pos == pos){
				DBG puts("Singular Update");
				sing_pos = pos;
				val = uv;
				return;
			} else {
				DBG printf("Pushing pre-\n");
				insert_val(sing_pos, val);
				DBG puts("And...");
				insert_val(pos, uv);
			}
		} else insert_val(pos,uv);
	}
	
	ll range(int a,int b){
		if(r<a || b<l) return 0;
		if(lp==0 && rp==0 && sing_pos!=-1 && a<=sing_pos && sing_pos<=b) return val;
		if(a<=l && r<=b){
			return val;
		}
		ll ret=0;
		if(lp) ret=gcd2(ret, lp->range(a,b));
		if(rp) ret=gcd2(ret, rp->range(a,b));
		DBG printf(">>> range %d~%d, get %d~%d : ret %lld\n",l,r,a,b,ret);
		return ret;
	}
};

int n,m;

struct node2 {
	node *p;
	int l,r;
	node2 *lp, *rp;
	node2(int a,int b){
		l=a; r=b;
		p=new node(0, m-1);
		lp=0; rp=0;
	}

	void update2(int x,int y,ll val){
		if(x<l || r<x) return;
		DBG printf("\nI am %d~%d. updating %d,%d / val %lld\n", l,r,x,y,val);
		if(l==r){
			DBG puts("Tada update");
			p->update(y,val);
			return;
		}
		int mid=(l+r)/2;
		ll yv=0;
		if(x<=mid){
			if(!lp) lp=new node2(l, mid);
			lp->update2(x,y,val);
		} else {
			if(!rp) rp=new node2(mid+1, r);
			rp->update2(x,y,val);
		}
		yv=gcd2(lp?(lp->p->range(y,y)):0, rp?(rp->p->range(y,y)):0);
		DBG printf("%d~%d of %d is %lld\n", l, r, y, yv);
		p->update(y, yv);
	}

	ll range(int a,int b,int x,int y){
		if(a<=l && r<=b){
			//printf("%d~%d full contain; asking %d~%d\n", l,r,x,y);
			return p->range(x,y);
		}
		if(r<a || b<l) return 0;
		ll ret=0;
		if(lp) ret=gcd2(ret, lp->range(a,b,x,y));
		if(rp) ret=gcd2(ret, rp->range(a,b,x,y));
		//printf("xrange %d~%d; ask %d~%d, %d~%d: %lld\n",l,r,a,b,x,y,ret);
		return ret;
	}
} *root=0;

void init(int R, int C) {
	n=R; m=C;
	root=new node2(0, n-1);
}

void update(int P, int Q, long long K) {
	//putchar(10);
	root->update2(P, Q, K);
}

long long calculate(int P, int Q, int U, int V) {
    return root->range(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 3 ms 384 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 4 ms 620 KB Output is correct
4 Correct 2 ms 620 KB Output is correct
5 Correct 3 ms 652 KB Output is correct
6 Correct 3 ms 800 KB Output is correct
7 Correct 2 ms 800 KB Output is correct
8 Correct 2 ms 800 KB Output is correct
9 Correct 3 ms 800 KB Output is correct
10 Correct 2 ms 800 KB Output is correct
11 Correct 3 ms 800 KB Output is correct
12 Correct 2 ms 800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 824 KB Output is correct
2 Correct 2 ms 828 KB Output is correct
3 Correct 2 ms 832 KB Output is correct
4 Correct 998 ms 14156 KB Output is correct
5 Correct 647 ms 18408 KB Output is correct
6 Correct 855 ms 20000 KB Output is correct
7 Correct 1051 ms 24224 KB Output is correct
8 Correct 612 ms 26848 KB Output is correct
9 Correct 1047 ms 33320 KB Output is correct
10 Correct 981 ms 37596 KB Output is correct
11 Correct 3 ms 37596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 37596 KB Output is correct
2 Correct 3 ms 37596 KB Output is correct
3 Correct 4 ms 37596 KB Output is correct
4 Correct 2 ms 37596 KB Output is correct
5 Correct 2 ms 37596 KB Output is correct
6 Correct 3 ms 37596 KB Output is correct
7 Correct 2 ms 37596 KB Output is correct
8 Correct 2 ms 37596 KB Output is correct
9 Correct 2 ms 37596 KB Output is correct
10 Correct 2 ms 37596 KB Output is correct
11 Correct 3 ms 37596 KB Output is correct
12 Correct 1750 ms 48788 KB Output is correct
13 Correct 3079 ms 48788 KB Output is correct
14 Correct 450 ms 48788 KB Output is correct
15 Correct 3484 ms 56956 KB Output is correct
16 Correct 294 ms 64828 KB Output is correct
17 Correct 1437 ms 65356 KB Output is correct
18 Correct 2440 ms 75544 KB Output is correct
19 Correct 2165 ms 80748 KB Output is correct
20 Correct 1934 ms 85832 KB Output is correct
21 Correct 2 ms 85832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 85832 KB Output is correct
2 Correct 3 ms 85832 KB Output is correct
3 Correct 3 ms 85832 KB Output is correct
4 Correct 2 ms 85832 KB Output is correct
5 Correct 2 ms 85832 KB Output is correct
6 Correct 3 ms 85832 KB Output is correct
7 Correct 2 ms 85832 KB Output is correct
8 Correct 2 ms 85832 KB Output is correct
9 Correct 3 ms 85832 KB Output is correct
10 Correct 3 ms 85832 KB Output is correct
11 Correct 3 ms 85832 KB Output is correct
12 Correct 954 ms 87984 KB Output is correct
13 Correct 638 ms 92308 KB Output is correct
14 Correct 902 ms 93804 KB Output is correct
15 Correct 1018 ms 98204 KB Output is correct
16 Correct 612 ms 100620 KB Output is correct
17 Correct 963 ms 106964 KB Output is correct
18 Correct 1000 ms 111364 KB Output is correct
19 Correct 1675 ms 122408 KB Output is correct
20 Correct 3400 ms 122408 KB Output is correct
21 Correct 438 ms 122408 KB Output is correct
22 Correct 3558 ms 130560 KB Output is correct
23 Correct 359 ms 138336 KB Output is correct
24 Correct 1506 ms 139016 KB Output is correct
25 Correct 2742 ms 149056 KB Output is correct
26 Correct 1894 ms 154352 KB Output is correct
27 Correct 1770 ms 159216 KB Output is correct
28 Correct 867 ms 198980 KB Output is correct
29 Correct 2285 ms 204700 KB Output is correct
30 Correct 6987 ms 213696 KB Output is correct
31 Correct 7476 ms 213696 KB Output is correct
32 Correct 1047 ms 213696 KB Output is correct
33 Correct 1432 ms 213696 KB Output is correct
34 Correct 550 ms 241008 KB Output is correct
35 Correct 2017 ms 241008 KB Output is correct
36 Correct 3541 ms 256000 KB Output is correct
37 Correct 2680 ms 256000 KB Output is correct
38 Correct 3130 ms 256000 KB Output is correct
39 Correct 2379 ms 256000 KB Output is correct
40 Correct 2 ms 256000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256000 KB Output is correct
2 Correct 3 ms 256000 KB Output is correct
3 Correct 3 ms 256000 KB Output is correct
4 Correct 2 ms 256000 KB Output is correct
5 Correct 2 ms 256000 KB Output is correct
6 Correct 2 ms 256000 KB Output is correct
7 Correct 2 ms 256000 KB Output is correct
8 Correct 2 ms 256000 KB Output is correct
9 Correct 3 ms 256000 KB Output is correct
10 Correct 3 ms 256000 KB Output is correct
11 Correct 3 ms 256000 KB Output is correct
12 Correct 892 ms 256000 KB Output is correct
13 Correct 563 ms 256000 KB Output is correct
14 Correct 746 ms 256000 KB Output is correct
15 Correct 944 ms 256000 KB Output is correct
16 Correct 592 ms 256000 KB Output is correct
17 Correct 921 ms 256000 KB Output is correct
18 Correct 946 ms 256000 KB Output is correct
19 Correct 1686 ms 256000 KB Output is correct
20 Correct 3191 ms 256000 KB Output is correct
21 Correct 456 ms 256000 KB Output is correct
22 Correct 3666 ms 256000 KB Output is correct
23 Correct 338 ms 256000 KB Output is correct
24 Correct 1477 ms 256000 KB Output is correct
25 Correct 2982 ms 256000 KB Output is correct
26 Correct 2298 ms 256000 KB Output is correct
27 Correct 2020 ms 256000 KB Output is correct
28 Correct 949 ms 256000 KB Output is correct
29 Correct 2257 ms 256000 KB Output is correct
30 Correct 7153 ms 256000 KB Output is correct
31 Correct 6903 ms 256000 KB Output is correct
32 Correct 910 ms 256000 KB Output is correct
33 Correct 1171 ms 256000 KB Output is correct
34 Correct 401 ms 256000 KB Output is correct
35 Correct 1701 ms 256000 KB Output is correct
36 Correct 3858 ms 256000 KB Output is correct
37 Correct 3136 ms 256000 KB Output is correct
38 Correct 2896 ms 256000 KB Output is correct
39 Correct 1363 ms 256000 KB Output is correct
40 Correct 3637 ms 256000 KB Output is correct
41 Correct 9488 ms 256000 KB Output is correct
42 Correct 8461 ms 256000 KB Output is correct
43 Correct 818 ms 256000 KB Output is correct
44 Correct 1454 ms 256000 KB Output is correct
45 Correct 2522 ms 256000 KB Output is correct
46 Correct 4302 ms 256000 KB Output is correct
47 Correct 4581 ms 256000 KB Output is correct
48 Correct 4451 ms 256000 KB Output is correct
49 Correct 2 ms 256000 KB Output is correct