답안 #349706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349706 2021-01-18T08:47:54 Z amunduzbaev 게임 (IOI13_game) C++14
0 / 100
1 ms 492 KB
#include "game.h"

#ifndef EVAL
#include "grader.cpp"
#endif

#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vll vector<ll>
#define vii vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define cnt(a)__builtin_popcount(a)
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}

int gcd2(long long X, long long Y) {
    long long tmp;
    while (X != Y && Y != 0) {
        tmp = X;
        X = Y;
        Y = tmp % Y;
    }
    return X;
}

int sx, sy;
vector<vii> tree;

void update_r(int x, int y, int val, int lx, int rx, int ly, int ry, int xx, int yy){
	if(ly == ry){
		if(lx == rx) tree[xx][yy] = val;
		else tree[xx][yy] = gcd2(tree[xx*2][yy], tree[xx*2+1][yy]); 
	}else{
		int m = (ly + ry)>>1;
		if(y <= m) update_r(x, y, val, lx, rx, ly, m, xx, yy*2);
		else update_r(x, y, val, lx, rx, m+1, rx, xx, yy*2+1);
		tree[xx][yy] = gcd2(tree[xx][yy*2], tree[xx][yy*2+1]);
	}
}

void upd(int x, int y, int val, int lx, int rx, int xx){
	if(lx != rx){
		int m = (lx + rx)>>1;
		if(x <= m) upd(x, y, val, lx, m, xx*2);
		else upd(x, y, val, m+1, rx, xx*2+1);
	}
	update_r(x, y, val, lx, rx, 1, sy, xx, 1);
}

int qqy(int ly, int ry, int xx, int qly, int qry, int yy){
	if(ly > qry || ry < qly) return -1;
	if(ly >= qly && ry <= qry) return tree[xx][yy];
	
	int m = (ly + ry)>>1;
	int res1 = qqy(ly, m, xx, qly, qry, yy*2);
	int res2 = qqy(m+1, ry, xx, qly, qry, yy*2+1);
	
	if(res1 == -1) return res2;
	else if(res2 == -1) return res1;
	else return gcd2(res1, res2);
}

int qq(int lx, int rx, int qlx, int qrx, int qly, int qry, int xx){
	if(lx > qrx || rx < qlx) return -1;
	if(lx >= qlx && rx <= qrx) return qqy(1, sy, xx, qly, qry, 1);
	
	int m = (lx + rx)>>1;
	int res1 = qq(lx, m, qlx, qrx, qly, qry, xx*2);
	int res2 = qq(m+1, rx, qlx, qrx, qly, qry, xx*2+1);
	
	if(res2 == -1) return res1;
	else if(res1 == -1) return res2;
	else return gcd2(res1, res2);
}

void init(int R, int C) {
	sx = 1, sy = 1;
	while(sx < R) sx <<=1;
	while(sy < C) sy <<=1;
	
	tree.assign(sx, vector<int>(sy, 0));
}

void update(int P, int Q, long long K) {
    upd(P, Q, K, 1, sx, 1);
}

ll calculate(int x, int y, int xx, int yy) {
    return qq(1, sx, min(x, xx), max(x, xx), min(y, yy), max(y, yy), 1);
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 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 492 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 492 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 492 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 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -