답안 #306435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306435 2020-09-25T15:05:32 Z Temmie 게임 (IOI13_game) C++17
0 / 100
1 ms 512 KB
#include "game.h"
#include <bits/stdc++.h>

typedef long long ll;

const ll size = 1073741824;

struct Node {
	
	Node* tl, * tr, * bl, * br;
	
	ll topLx, topLy, recSize;
	
	ll valu;
	
	Node(ll X, ll Y, ll recsize) :
	tl(nullptr), tr(nullptr), bl(nullptr), br(nullptr),
	topLx(X), topLy(Y), recSize(recsize),
	valu(0)
	{ }
	
	~Node() {
		if (tl) delete(tl);
		if (tl) delete(tr);
		if (bl) delete(bl);
		if (br) delete(br);
	}
	
	void update(ll x, ll y, ll val) {
		if (x < topLx || x >= topLx + recSize || y < topLy || y >= topLy + recSize) return;
		if (recSize == 1LL) { valu = val; return; }
		ll xmid = (recSize + topLx + topLx) >> 1LL;
		ll ymid = (recSize + topLy + topLy) >> 1LL;
		if (!tl) tl = new Node(topLx, topLy, recSize >> 1LL);
		if (!bl) bl = new Node(topLx, ymid, recSize >> 1LL);
		if (!tr) tr = new Node(xmid, topLy, recSize >> 1LL);
		if (!br) br = new Node(xmid, ymid, recSize >> 1LL);
		tl->update(x, y, val);
		bl->update(x, y, val);
		tr->update(x, y, val);
		br->update(x, y, val);
		valu = std::gcd(tl->valu, std::gcd(tr->valu, std::gcd(bl->valu, br->valu)));
	}
	
	ll get(ll xl, ll yl, ll xr, ll yr) {
		if (xr <= topLx || xl >= topLx + recSize || yr <= topLy || yl >= topLx + recSize) return 0;
		if (xl <= topLx && xr >= topLx + recSize && yl <= topLy && yr >= topLy + recSize) return valu;
		return std::gcd(tl->get(xl, yl, xr, yr), std::gcd(tr->get(xl, yl, xr, yr), std::gcd(bl->get(xl, yl, xr, yr), br->get(xl, yl, xr, yr))));
	}
	
};

Node* head = nullptr;

void init(int r, int c) { head = new Node(0, 0, size); }

void update(int r, int c, ll val) { head->update(c, r, val); }

ll calculate(int tr, int tl, int br, int bl) { return head->get(tl, tr, bl + 1, br + 1); }
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -