답안 #171170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171170 2019-12-27T16:51:13 Z dennisstar 게임 (IOI13_game) C++11
0 / 100
2 ms 376 KB
#include "game.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define ryan bear
#define all(V) ((V).begin()), ((V).end())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef vector<int> vim;
typedef vector<ll> vlm;
 
int R, C;
struct dt1 {
	dt1 *l1, *l2, *r1, *r2;
	ll dt;
	dt1() {l1=l2=r1=r2=NULL; dt=0;}
	inline void upd(int x, int y, ll val, int xs, int xe, int ys, int ye) {
		if (xs==xe&&ys==ye) {dt=val; return ;}
		int xm=(xs+xe)/2, ym=(ys+ye)/2;
		if (x<=xm) {
			if (y<=ym) {
				if (!l1) l1=new dt1();
				l1->upd(x, y, val, xs, xm, ys, ym);
			}
			else {
				if (!r1) r1=new dt1();
				r1->upd(x, y, val, xs, xm, ym+1, ye);
			}
		}
		else {
			if (y<=ym) {
				if (!l2) l2=new dt1();
				l2->upd(x, y, val, xm+1, xe, ys, ym);
			}
			else {
				if (!r2) r2=new dt1();
				r2->upd(x, y, val, xm+1, xe, ym+1, ye);
			}
		}
		ll L1, L2, R1, R2;
		L1=(l1?l1->dt:0); L2=(l2?l2->dt:0);
		R1=(r1?r1->dt:0); R2=(r2?r2->dt:0);
		dt=__gcd(__gcd(L1, L2), __gcd(R1, R2));
	}
	inline ll get(int x1, int x2, int y1, int y2, int xs, int xe, int ys, int ye) {
		if (x1<=xs&&xe<=x2&&y1<=ys&&ye<=y2) return dt;
		int xm=(xs+xe)/2, ym=(ys+ye)/2;
		ll L1, L2, R1, R2; L1=L2=R1=R2=0;
		if (xm<=x2) {
			if (ym<=y2) L1=(l1?l1->get(x1, x2, y1, y2, xs, xm, ys, ym):0);
			if (y1<=ym+1) R1=(r1?r1->get(x1, x2, y1, y2, xs, xm, ym+1, ye):0);
		}
		if (x1<=xm+1) {
			if (ym<=y2) L2=(l2?l2->get(x1, x2, y1, y2, xm+1, xe, ys, ym):0);
			if (y1<=ym+1) R2=(r2?r2->get(x1, x2, y1, y2, xm+1, xe, ym+1, ye):0);
		}
		return __gcd(__gcd(L1, L2), __gcd(R1, R2));
	}
};
 
dt1 *root=new dt1();
 
void init(int r_, int c_) {
	R=r_, C=c_;
}
 
void update(int P, int Q, ll K) {
	root->upd(P, Q, K, 0, R-1, 0, C-1);
}
 
ll calculate(int P, int Q, int U, int V) {
    return root->get(P, U, Q, V, 0, R-1, 0, C-1);
}

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 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Incorrect 2 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -