제출 #281988

#제출 시각아이디문제언어결과실행 시간메모리
281988shayan_p게임 (IOI13_game)C++14
100 / 100
3572 ms57080 KiB
// And you curse yourself for things you never done
 
#include<bits/stdc++.h>
#include "game.h"
 
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
 
const int inf = 1e9 + 10;
 
int N, M;
 
struct node{
    ll g = 0, x = 0;
    node *L = 0, *R = 0;
    int pos = 0, S = 0, MN, MX;
    node(int _pos, ll _g){
	pos = _pos, g = _g, x = _g, MN = MX = _pos;
	S = 1;
    }
    void rest(int _pos, ll _g){
	pos = _pos, g = _g, x = _g, MN = MX = _pos;
	S = 1;
    }
    ll ask(int _pos){
	if(pos == _pos)
	    return x;
	if(_pos < pos)
	    return (L ? L->ask(_pos) : 0);
	else
	    return (R ? R->ask(_pos) : 0);
    }
    ll ask(int f, int s){
	if(f <= MN && MX < s)
	    return g;
	if(s <= MN || MX < f)
	    return 0;
	ll ans = 0;
	if(f <= pos && pos < s)
	    ans = x;
	if(L)
	    ans = __gcd(ans, L->ask(f, s));
	if(R)
	    ans = __gcd(ans, R->ask(f, s));
	return ans;
    }
};
void build(node* nw){
    nw->S = (nw->L ? nw->L->S : 0) + (nw->R ? nw->R->S : 0) + 1;
    nw->g = __gcd(nw->x, __gcd( nw->L ? nw->L->g : 0, nw->R ? nw->R->g : 0 ));
    nw->MN = min({nw->pos, nw->L ? nw->L->MN : inf, nw->R ? nw->R->MN : inf});
    nw->MX = max({nw->pos, nw->L ? nw->L->MX : -inf, nw->R ? nw->R->MX : -inf});
}
void split(node* nw, int x, node *&L, node *&R){
    if(nw == 0){
	L = R = 0;
	return;
    }
    if(nw->pos < x){
	split(nw->R, x, L, R);
	nw->R = L;
	build(nw);
	L = nw;
    }
    else{
	split(nw->L, x, L, R);
	nw->L = R;
	build(nw);
	R = nw;
    }
}
node* merge(node *A, node *B){
    if(A == 0)
	return B;
    if(B == 0)
	return A;
    if((rand() % (A->S + B->S)) < A->S){
	A->R = merge(A->R, B);
	build(A);
	return A;
    }
    else{
	B->L = merge(A, B->L);
	build(B);
	return B;
    }
    assert(0);
} 
void _put(node *&nw, int pos, ll x){
    node *A, *B, *C;
    split(nw, pos, A, B);
    split(B, pos+1, B, C);
    if(B == 0)
	B = new node(pos, x);
    else
	B->rest(pos, x);
    nw = merge(A, merge(B, C));
}
 
struct node2{
    node* g = 0;
    node2 *L = 0, *R = 0;
    void put(int posx, int posy, ll x, int l = 0, int r = N){
	ll num = x;
	if(r-l > 1){
	    int mid = (l+r) >> 1;
	    if(posx < mid){
		if(!L)
		    L = new node2();
		L->put(posx, posy, x, l, mid);
	    }
	    else{
		if(!R)
		    R = new node2();
		R->put(posx, posy, x, mid, r);
	    }	    
	    num = __gcd(L ? L->g->ask(posy) : 0, R ? R->g->ask(posy) : 0);
	}
	if(!g)
	    g = new node(posy, num);
	else	    
	    _put(g, posy, num);
    }
    ll ask(int f, int s, int ff, int ss, int l = 0, int r = N){
	if(r <= f || s <= l)
	    return 0;
	if(f <= l && r <= s)
	    return g ? g->ask(ff, ss) : 0;
	int mid = (l+r) >> 1;
	return __gcd(L ? L->ask(f, s, ff, ss, l, mid) : 0, R ? R->ask(f, s, ff, ss, mid, r) : 0);
    }
};
 
node2* root;
 
void init(int N, int M){
    srand(time(0));
    ::N = N, ::M = M;
    root = new node2();
}
void update(int x, int y, ll w){
    root->put(x, y, w);
}
ll calculate(int x, int y, int xx, int yy){
    return root->ask(x, ++xx, y, ++yy);
}

컴파일 시 표준 에러 (stderr) 메시지

grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   18 |  int res;
      |      ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...