Submission #336444

# Submission time Handle Problem Language Result Execution time Memory
336444 2020-12-15T10:46:43 Z ewwdsgfvsd Klasika (COCI20_klasika) C++17
33 / 110
737 ms 524292 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
/*#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")*/
using namespace std;
using ll = long long int;
#define F first
#define S second
#define pb push_back
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int N=4e5+10,LN=31,SQ=200;
const ll INF=1e18;
const int MOD=1000000007 /*998244353*/;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
#define ordered_set tree<pair<pll,ll>, null_type,less<pair<pll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
    ll ans=1;
    while (y != 0) {
        if (y & 1) ans = ans * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}
struct tr{
    vector<ll> nx[2];
    ll k;
    void add(ll x) {
        ll v = 0;
        for (ll i=LN-1;i>=0;i--) {
            ll y=bool(x&(1<<i));
            if(!nx[y][v]) nx[y][v] = k++;
            v = nx[y][v];
        }
    }
    ll get(ll x){
        ll res=0,v=0;
        if(k==1) return 0;
        for(ll i=LN-1; i>=0; i--){
            ll y=((x&(1<<i))!=0);
            y=1-y;
            if(nx[y][v]) v=nx[y][v],res+=(1<<i);
            else v=nx[1-y][v];
        }
        return res;
    }
};
tr f[4*N];
ll q,a[N],t=1,st[N],fn[N],g=2;
vector<pair<ll,pll>> qu;
vector<pll> adj[N];
void dfs(ll v){
    st[v]=t++;
    for(pll p :adj[v]) a[p.F]=a[v]^p.S,dfs(p.F);
    fn[v]=t;
}
void build(ll v, ll l, ll r) {
    f[v].k=1;
    f[v].nx[0].resize((r-l+2)*(LN-1),0);
    f[v].nx[1].resize((r-l+2)*(LN-1),0);
    if (r-l==1) return;
    ll m=(l+r)/2;
    build(v*2,l,m);
    build(v*2+1,m,r);
}
void upd(ll v, ll l, ll r, ll p, ll x){
    f[v].add(x);
    //cout << l << ' ' << r << ' ' << f[v].get(0) << '\n';
    if(r-l==1) return;
    ll m=(l+r)/2;
    if(p<m) upd(v*2,l,m,p,x);
    else upd(v*2+1,m,r,p,x);
}
ll get(ll v, ll l, ll r, ll tl, ll tr, ll x){
    if(tl>=tr) return 0;
    if(l==tl && r==tr) return f[v].get(x);
    ll m=(l+r)/2;
    return max(get(v*2,l,m,tl,min(m,tr),x),get(v*2+1,m,r,max(m,tl),tr,x));
}
int main(){
    fast_io;
    cin >> q;
    for(ll i=0; i<q; i++){
        string s;
        ll c,x,y;
        cin >> s >> x >> y;
        if(s[0]=='A') c=0;
        else c=1;
        if(c==0){
            qu.pb({c,{x,g}});
            adj[x].pb({g++,y});
        }else qu.pb({c,{x,y}});
    }
    dfs(1);
    build(1,1,t);
    upd(1,1,t,st[1],a[1]);
    for(ll i=0; i<q; i++){
        ll x=qu[i].S.F,y=qu[i].S.S;
        if(qu[i].F==0){
            //cout << i << ' ' << y << '\n';
            upd(1,1,t,st[y],a[y]);
        }else{
            //cout << (a[x]^a[y]) << '\n';
            cout << get(1,1,t,st[y],fn[y],a[x]) << '\n';
        }
    }
    //cout << st[4] << ' ' << fn[4] << ' ' << st[5] << ' ' << fn[5] << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 66 ms 97644 KB Output is correct
2 Correct 68 ms 97900 KB Output is correct
3 Correct 68 ms 98156 KB Output is correct
4 Correct 65 ms 98284 KB Output is correct
5 Correct 67 ms 97644 KB Output is correct
6 Correct 65 ms 97900 KB Output is correct
7 Correct 65 ms 98028 KB Output is correct
8 Correct 65 ms 98412 KB Output is correct
9 Correct 65 ms 97792 KB Output is correct
10 Correct 67 ms 97900 KB Output is correct
11 Correct 65 ms 98156 KB Output is correct
12 Correct 66 ms 98412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 97644 KB Output is correct
2 Correct 68 ms 97900 KB Output is correct
3 Correct 68 ms 98156 KB Output is correct
4 Correct 65 ms 98284 KB Output is correct
5 Correct 67 ms 97644 KB Output is correct
6 Correct 65 ms 97900 KB Output is correct
7 Correct 65 ms 98028 KB Output is correct
8 Correct 65 ms 98412 KB Output is correct
9 Correct 65 ms 97792 KB Output is correct
10 Correct 67 ms 97900 KB Output is correct
11 Correct 65 ms 98156 KB Output is correct
12 Correct 66 ms 98412 KB Output is correct
13 Correct 70 ms 100332 KB Output is correct
14 Correct 72 ms 103404 KB Output is correct
15 Correct 78 ms 106732 KB Output is correct
16 Correct 80 ms 109676 KB Output is correct
17 Correct 69 ms 100076 KB Output is correct
18 Correct 73 ms 103164 KB Output is correct
19 Correct 76 ms 106476 KB Output is correct
20 Correct 79 ms 109420 KB Output is correct
21 Correct 69 ms 100204 KB Output is correct
22 Correct 84 ms 103148 KB Output is correct
23 Correct 75 ms 106604 KB Output is correct
24 Correct 81 ms 109420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 737 ms 491032 KB Output is correct
2 Runtime error 372 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 66 ms 97644 KB Output is correct
2 Correct 68 ms 97900 KB Output is correct
3 Correct 68 ms 98156 KB Output is correct
4 Correct 65 ms 98284 KB Output is correct
5 Correct 67 ms 97644 KB Output is correct
6 Correct 65 ms 97900 KB Output is correct
7 Correct 65 ms 98028 KB Output is correct
8 Correct 65 ms 98412 KB Output is correct
9 Correct 65 ms 97792 KB Output is correct
10 Correct 67 ms 97900 KB Output is correct
11 Correct 65 ms 98156 KB Output is correct
12 Correct 66 ms 98412 KB Output is correct
13 Correct 70 ms 100332 KB Output is correct
14 Correct 72 ms 103404 KB Output is correct
15 Correct 78 ms 106732 KB Output is correct
16 Correct 80 ms 109676 KB Output is correct
17 Correct 69 ms 100076 KB Output is correct
18 Correct 73 ms 103164 KB Output is correct
19 Correct 76 ms 106476 KB Output is correct
20 Correct 79 ms 109420 KB Output is correct
21 Correct 69 ms 100204 KB Output is correct
22 Correct 84 ms 103148 KB Output is correct
23 Correct 75 ms 106604 KB Output is correct
24 Correct 81 ms 109420 KB Output is correct
25 Correct 737 ms 491032 KB Output is correct
26 Runtime error 372 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
27 Halted 0 ms 0 KB -