# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
122143 | yusufake | 게임 (IOI13_game) | C++98 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "game.h"
using namespace std;
#define _ int v, int tl, int tr
#define tm (tl+tr >> 1)
#define sol L[v],tl,tm
#define sag R[v],tm+1,tr
#define mp make_pair
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef pair < int , int > pp;
const int mod = 1e9 - 1;
const int N = 22000 * 23 * 23;
int Y[N],L[N],R[N],id = 1;
ll s[N],t;
int posx,posy,lx,rx,ly,ry;
// 0 is empty node
// s[0] should be ineffective element
// Y[0], L[0], and R[0] should be 0
// 1 is the root of the -x axis segment tree
// Y[v] is the root of the segment tree of the interval that corresponds to node 'v' in -x axis segment tree
ll gcd(ll u, ll v) {
ll r;
while (v != 0) { r = u % v; u = v; v = r; }
return u;
}
ll qry_y(_) {
if(ly > tr || ry < tl || !v) return 0;
if (ly <= tl && tr <= ry) return s[v];
return gcd(qry_y(sol) , qry_y(sag));
}
ll qry_x(_) {
if(lx > tr || rx < tl) return 0;
if (lx <= tl && tr <= rx) return qry_y(Y[v], 0, mod);
return gcd(qry_x(sol) , qry_x(sag));
}
void up_y(_, int r1, int r2){
if(tl == tr){
s[v] = r1 || r2 ? gcd(s[r1] , s[r2]) : t;
return;
}
if(posy > tm) { if(!R[v]) R[v] = ++id; up_y(sag,R[r1],R[r2]); }
else { if(!L[v]) L[v] = ++id; up_y(sol,L[r1],L[r2]); }
s[v] = gcd(s[ L[v] ] , s[ R[v] ]);
}
void up_x(_, int posx, int posy, ll t){
if(tl < tr){
if(posx > tm) { if(!R[v]) R[v] = ++id; up_x(sag); }
else { if(!L[v]) L[v] = ++id; up_x(sol); }
}
if(!Y[v]) Y[v] = ++id;
up_y(Y[v],0,mod,Y[ L[v] ],Y[ R[v] ]);
}
void update(int px, int py, ll tt){
posx = px;
posy = py;
t = tt;
up_x(1,0,mod);
}
ll calculate(int aalx, int aaly, int aarx, int aary){
lx = aalx; rx = aarx;
ly = aaly; ry = aary;
return qry_x(1,0,mod);
}
void init(int a, int b) {}