| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 43156 | yusufake | Game (IOI13_game) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "game.h"
using namespace std;
#define tm (tl+tr >> 1)
#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 + 7;
const int N = 2e5 + 5;
inline ll gcd(ll u, ll v) {
ll r;
while (v != 0) { r = u % v; u = v; v = r; }
return u;
}
struct node{
ll x;
struct node *l, *r, *to_y;
node() { x = 0; l = r = to_y = NULL; }
node* nw(){
node *p = (node *)malloc(sizeof(node));
return p;
}
ll qry_y(int tl, int tr, int ly, int ry) {
if(ly > tr || ry < tl) return 0;
if (ly <= tl && tr <= ry) return x;
return gcd(l ? l->qry_y(tl,tm,ly,ry) : 0 , r ? r->qry_y(tm+1,tr,ly,ry) : 0);
}
ll qry_x(int tl, int tr, int lx, int rx, int ly, int ry) {
if(lx > tr || rx < tl) return 0;
if (lx <= tl && tr <= rx) return to_y ? to_y->qry_y(0,mod,ly,ry) : 0;
return gcd(l ? l->qry_x(tl,tm,lx,rx,ly,ry) : 0 ,
r ? r->qry_x(tm+1,tr,lx,rx,ly,ry) : 0);
}
void up_y(int tl, int tr, int py, ll val){
if(tl == tr){
x = val; return;
}
if(py > tm) { if(r == NULL) r = new node; r -> up_y(tl,tm,py,val); }
else { if(l == NULL) l = new node; l -> up_y(tm+1,tr,py,val); }
x = gcd(l ? l->x : 0 , r ? r->x : 0);
}
void up_x(int tl, int tr, int px, int py, ll val){
if(tl < tr){
if(px > tm) { if(r == NULL) r = new node r -> up_x(tl,tm,px,py,val); }
else { if(l == NULL) l = new node l -> up_x(tm+1,tr,px,py,val); }
}
if(tl < tr)
val = gcd(l ? l->qry_y(0,mod,py,py) : 0 , r ? r->qry_y(0,mod,py,py) : 0);
if(to_y == NULL) to_y = new node; to_y -> up_y(0,mod,py,val);
}
} root;
void update(int x, int y, ll val){
root.up_x(0,mod,x,y,val);
}
ll calculate(int lx, int ly, int rx, int ry){
return root.qry_x(0,mod,lx,rx,ly,ry);
}
void init(int a, int b) {}
