답안 #1102569

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102569 2024-10-18T10:33:47 Z ttamx 게임 (IOI13_game) C++17
0 / 100
3 ms 592 KB
#include "game.h"
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

ll gcd2(ll X,ll Y){
    while(Y!=0)tie(X,Y)=make_pair(Y,X%Y);
    return X;
}

ll n,m;

struct SegTree{
    struct Node;
    using Ptr = Node*;
    struct Node{
        ll val;
        Ptr l,r;
        Node():val(0LL),l(),r(){}
    };
    Ptr root;
    SegTree():root(){}
    ll get(Ptr t){
        return t?t->val:0LL;
    }
    void modify(ll l,ll r,Ptr &t,ll x,ll v){
        if(!t)t=new Node();
        if(l==r)return void(t->val=v);
        ll m=(l+r)/2;
        if(x<=m)modify(l,m,t->l,x,v);
        else modify(m+1,r,t->r,x,v);
        t->val=gcd2(get(t->l),get(t->r));
    }
    void modify(ll x,ll v){
        modify(0,1e9,root,x,v);
    }
    ll query(ll l,ll r,Ptr &t,ll x,ll y){
        if(y<l||r<x||!t)return 0LL;
        if(x<=l&&r<=y)return t->val;
        ll m=(l+r)/2;
        return gcd2(query(l,m,t->l,x,y),query(m+1,r,t->r,x,y));
    }
    ll query(ll x,ll y){
        return query(0,1e9,root,x,y);
    }
};

struct SegTree2D{
    struct Node;
    using Ptr = Node*;
    struct Node{
        SegTree tree;
        Ptr l,r;
        Node():tree(),l(),r(){}
    };
    Ptr root;
    SegTree2D():root(){}
    void modify(ll l,ll r,Ptr &t,ll x,ll y,ll v){
        if(!t)t=new Node();
        t->tree.modify(y,v);
        if(l==r)return;
        ll m=(l+r)/2;
        if(x<=m)modify(l,m,t->l,x,y,v);
        else modify(m+1,r,t->r,x,y,v);
    }
    void modify(ll x,ll y,ll v){
        modify(0,1e9,root,x,y,v);
    }
    ll query(ll l,ll r,Ptr &t,ll x,ll y,ll x2,ll y2){
        if(y<l||r<x||!t)return 0LL;
        if(x<=l&&r<=y)return t->tree.query(x2,y2);
        ll m=(l+r)/2;
        return gcd2(query(l,m,t->l,x,y,x2,y2),query(m+1,r,t->r,x,y,x2,y2));
    }
    ll query(ll x,ll y,ll x2,ll y2){
        return query(0,1e9,root,x,y,x2,y2);
    }
}seg;

void init(int R,int C){
    n=R,m=C;
}

void update(int P,int Q,ll K){
    seg.modify(P,Q,K);
}

ll calculate(int P,int Q,int U,int V){
    return seg.query(P,U,Q,V);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 3 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 3 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 2 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 2 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -