Submission #1136778

#TimeUsernameProblemLanguageResultExecution timeMemory
1136778t9unkubjGame (IOI13_game)C++20
63 / 100
3037 ms321536 KiB

#ifdef t9unkubj
#include"debug.cpp"
//#include"template_no_debug.h"
#else 
#include "game.h"
#define dbg(...) 199958
#endif

#undef _GLIBCXX_DEBUG
#pragma GCC optimize("O3")
using namespace std;
#include<bits/stdc++.h>
using ll=long long;
using ull=unsigned long long;
template<class T>using vc=vector<T>;
template<class T>using vvc=vc<vc<T>>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++)
#define DREP(i,n,m) for(ll i=(n);i>=(m);i--)
#define drep(i,n) for(ll i=((n)-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
template<class T,class F>
bool chmin(T &x, F y){
    if(x>y){
        x=y;
        return true;
    }
    return false;
}
template<class T, class F>
bool chmax(T &x, F y){
    if(x<y){
        x=y;
        return true;
    }
    return false;
}
double pass_time=0;

long long gcd2(long long X, long long Y) {
    long long tmp;
    while (X != Y && Y != 0) {
        tmp = X;
        X = Y;
        Y = tmp % Y;
    }
    return X;
}
constexpr int M=1<<30;
struct segtree{
    struct Node{
        Node*l;
        Node*r;
        ll val;
        Node():l(nullptr),r(nullptr),val(0){}
    };
    using np=Node*;
    np root;
    segtree()=default;
    void build(){
        root=new Node();
    }
    inline void maker(np&x){
        if(x==nullptr)x=new Node();
    }
    void internal_set(int l,int r,int i,ll x,np&now){
        if(l+1==r){
            now->val=x;
            return;
        }
        int mid=l+r>>1;
        
        maker(now->l);
        maker(now->r);
        if(l<=i&&i<mid){
            internal_set(l,mid,i,x,now->l);
        }else{
            internal_set(mid,r,i,x,now->r);
        }
        now->val=gcd2(now->l->val,now->r->val);
    }
    void set(int i,ll x){
        internal_set(0,M,i,x,root);
    }
    ll internal_prod(int nl,int nr,int l,int r,np&now){
        if(nr<=l||r<=nl){
            return 0;
        }
        if(l<=nl&&nr<=r){
            return now->val;
        }
        int mid=nl+nr>>1;
        maker(now->l);
        maker(now->r);
        return gcd2(internal_prod(nl,mid,l,r,now->l),
        internal_prod(mid,nr,l,r,now->r));
    }
    ll prod(ll l,ll r){
        return internal_prod(0,M,l,r,root);
    }
};

struct Segtree{
    struct Node2{
        Node2*l;
        Node2*r;
        segtree seg;
        Node2():l(nullptr),r(nullptr){
            seg.build();
        }
    };
    using np2=Node2*;
    np2 root;
    Segtree()=default;
    void build(){
        root=new Node2();
    }
    inline void maker(np2&x){
        if(x==nullptr)x=new Node2();
    }
    void internal_set(int l,int r,int i,int j,ll x,np2&now){
        if(l+1==r){
            (now->seg).set(j,x);
            return;
        }
        
        int mid=l+r>>1;
        
        maker(now->l);
        maker(now->r);
        
        if(l<=i&&i<mid){
            internal_set(l,mid,i,j,x,now->l);
        }else{
            internal_set(mid,r,i,j,x,now->r);
        }
        ll g1=(now->l)->seg.prod(j,j+1);
        ll g2=(now->r)->seg.prod(j,j+1);
        now->seg.set(j,gcd2(g1,g2));
    }
    void set(int i,int j,ll x){
        internal_set(0,M,i,j,x,root);
    }
    ll internal_prod(int nl,int nr,int l,int r,np2&now,ll L2,ll R2){
        if(nr<=l||r<=nl){
            return 0;
        }
        if(l<=nl&&nr<=r){
            return now->seg.prod(L2,R2);
        }
        int mid=nl+nr>>1;
        maker(now->l);
        maker(now->r);
        return gcd2(internal_prod(nl,mid,l,r,now->l,L2,R2),
        internal_prod(mid,nr,l,r,now->r,L2,R2));
    }
    ll prod(ll l,ll r,ll L2,ll R2){
        return internal_prod(0,M,l,r,root,L2,R2);
    }
};
Segtree seg;
void init(int R, int C) {
    seg.build();
}

void update(int P, int Q, long long K) {
    /* ... */
    seg.set(P,Q,K);
    dbg(seg.prod(P,P+1,Q,Q+1));
}

long long calculate(int P, int Q, int U, int V) {
    /* ... */
    return seg.prod(P,U+1,Q,V+1);
}
namespace judge{
    void run(){
        init(0,0);
        while(1){
            int t;
            cin>>t;
            if(t==1){
                int a,b,c;
                cin>>a>>b>>c;
                update(a,b,c);
            }else{
                int a,b,c,d;
                cin>>a>>b>>c>>d;
                dbg(calculate(a,b,c,d));
            }
        }
    }
};
//int main(){judge::run();}
#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...