Submission #18679

# Submission time Handle Problem Language Result Execution time Memory
18679 2016-02-14T02:55:21 Z suhgyuho_william Game (IOI13_game) C++
0 / 100
0 ms 126084 KB
#include "game.h"

#define lld long long

long long gcd(long long X, long long Y) {
    long long tmp;

    while (X != Y && Y != 0) {
        tmp = X;
        X = Y;
        Y = tmp % Y;
    }
    return X;
}

int nr,nc;
long long seg[4000][4000];

void init(int R, int C) {
    for(nr = 1; nr < R; nr *= 2);
    for(nc = 1; nc < C; nc *= 2);
}

void update(int P, int Q, long long K) {
	P++; Q++;
	int i,j;

	i = nr+P-1;
	while(i > 0){
		j = nc+Q-1; seg[i][j] = K; j /= 2;
		while(j > 0){
			seg[i][j] = gcd(seg[i][j*2],seg[i][(j*2)+1]);
			j /= 2;
		}
		i /= 2;
	}
}

int cnt1,cnt2;
int p1[100],p2[100];
int sr,er,sc,ec;
void find1(int node,int left,int right){
	if(er < left || right < sr) return;
	if(sr <= left && right <= er){
		cnt1++;
		p1[cnt1] = node;
		return;
	}
	int mid = (left+right)/2;
	find1(node*2,left,mid);
	find1((node*2)+1,mid+1,right);
}
void find2(int node,int left,int right){
	if(ec < left || right < sc) return;
	if(sc <= left && right <= ec){
		cnt2++;
		p2[cnt2] = node;
		return;
	}
	int mid = (left+right)/2;
	find2(node*2,left,mid);
	find2((node*2)+1,mid+1,right);
}

long long calculate(int P, int Q, int U, int V) {
	int i,j;
	long long ans = 0;

    P++; Q++; U++; V++;
	sr = P; er = U;
	sc = Q; ec = V;
	cnt1 = 0; find1(1,1,nr);
	cnt2 = 0; find2(1,1,nc);
	for(i=1; i<=cnt1; i++){
		for(j=1; j<=cnt2; j++){
			ans = gcd(ans,seg[p1[i]][p2[j]]);
		}
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 126084 KB Output is correct
2 Incorrect 0 ms 126084 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 126084 KB Output is correct
2 Incorrect 0 ms 126084 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 126084 KB Output is correct
2 Incorrect 0 ms 126084 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 126084 KB Output is correct
2 Incorrect 0 ms 126084 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 126084 KB Output is correct
2 Incorrect 0 ms 126084 KB Output isn't correct
3 Halted 0 ms 0 KB -