Submission #198515

# Submission time Handle Problem Language Result Execution time Memory
198515 2020-01-26T12:49:03 Z alishahali1382 Klasika (COCI20_klasika) C++14
33 / 110
3249 ms 524292 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("fast-math")
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define get(x, y) (((x)>>(y))&1)
 
const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG=31;
 
int n=1, m, k, u, v, x, y, t, L, R, X, ans;
int TR[MAXN*LOG][2], ts;
int par[MAXN], val[MAXN];
int stt[MAXN], fnt[MAXN], timer;
int typ[MAXN], A[MAXN], B[MAXN];
vector<int> G[MAXN];
set<int> vec[MAXN*LOG];
string s;

inline bool f(int v, int l, int r){
    auto it=vec[v].lower_bound(l);
    if (it==vec[v].end() || r<=*it) return 0;
    return 1;
}
 
void dfs(int node){
    stt[node]=timer++;
    for (int v:G[node]) dfs(v);
    fnt[node]=timer;
}
 
inline void Add(int X, int pos){
    int v=0;
    for (int i=LOG-1; ~i; i--){
        int c=get(X, i);
        if (!TR[v][c]) TR[v][c]=++ts;
        v=TR[v][c];
        vec[v].insert(pos);
    }
}
 
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin>>m;
    for (int i=1; i<=m; i++){
        cin>>s>>A[i]>>B[i];
        if (s=="Add"){
            par[++n]=A[i];
            val[n]=val[A[i]]^B[i];
            G[A[i]].pb(n);
            continue ;
        }
        typ[i]=1;
    }
    dfs(1);
    n=1;
    Add(0, stt[1]);
    
    for (int i=1; i<=m; i++){
        if (typ[i]){
            X=val[A[i]];    
            L=stt[B[i]];
            R=fnt[B[i]];
            ans=0;
            
            int v=0;
            for (int i=LOG-1; ~i; i--){
                int c=get(X, i)^1;
                if (TR[v][c] && f(TR[v][c], L, R)) ans|=(1<<i);
                else c^=1;
                v=TR[v][c];
            }
            
            cout<<ans<<'\n';
            continue ;
        }
        ++n;
        Add(val[n], stt[n]);
    }
    
    
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 171 ms 296476 KB Output is correct
2 Correct 187 ms 296456 KB Output is correct
3 Correct 186 ms 296440 KB Output is correct
4 Correct 177 ms 296672 KB Output is correct
5 Correct 188 ms 296312 KB Output is correct
6 Correct 188 ms 296440 KB Output is correct
7 Correct 182 ms 296568 KB Output is correct
8 Correct 174 ms 296568 KB Output is correct
9 Correct 174 ms 296312 KB Output is correct
10 Correct 172 ms 296568 KB Output is correct
11 Correct 174 ms 296440 KB Output is correct
12 Correct 192 ms 296568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 296476 KB Output is correct
2 Correct 187 ms 296456 KB Output is correct
3 Correct 186 ms 296440 KB Output is correct
4 Correct 177 ms 296672 KB Output is correct
5 Correct 188 ms 296312 KB Output is correct
6 Correct 188 ms 296440 KB Output is correct
7 Correct 182 ms 296568 KB Output is correct
8 Correct 174 ms 296568 KB Output is correct
9 Correct 174 ms 296312 KB Output is correct
10 Correct 172 ms 296568 KB Output is correct
11 Correct 174 ms 296440 KB Output is correct
12 Correct 192 ms 296568 KB Output is correct
13 Correct 175 ms 297080 KB Output is correct
14 Correct 180 ms 297720 KB Output is correct
15 Correct 182 ms 298360 KB Output is correct
16 Correct 183 ms 299000 KB Output is correct
17 Correct 192 ms 297080 KB Output is correct
18 Correct 179 ms 297592 KB Output is correct
19 Correct 183 ms 298360 KB Output is correct
20 Correct 180 ms 299000 KB Output is correct
21 Correct 176 ms 297080 KB Output is correct
22 Correct 195 ms 297720 KB Output is correct
23 Correct 185 ms 298360 KB Output is correct
24 Correct 184 ms 299000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1090 ms 366328 KB Output is correct
2 Correct 2103 ms 431608 KB Output is correct
3 Correct 3249 ms 495480 KB Output is correct
4 Runtime error 2895 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 171 ms 296476 KB Output is correct
2 Correct 187 ms 296456 KB Output is correct
3 Correct 186 ms 296440 KB Output is correct
4 Correct 177 ms 296672 KB Output is correct
5 Correct 188 ms 296312 KB Output is correct
6 Correct 188 ms 296440 KB Output is correct
7 Correct 182 ms 296568 KB Output is correct
8 Correct 174 ms 296568 KB Output is correct
9 Correct 174 ms 296312 KB Output is correct
10 Correct 172 ms 296568 KB Output is correct
11 Correct 174 ms 296440 KB Output is correct
12 Correct 192 ms 296568 KB Output is correct
13 Correct 175 ms 297080 KB Output is correct
14 Correct 180 ms 297720 KB Output is correct
15 Correct 182 ms 298360 KB Output is correct
16 Correct 183 ms 299000 KB Output is correct
17 Correct 192 ms 297080 KB Output is correct
18 Correct 179 ms 297592 KB Output is correct
19 Correct 183 ms 298360 KB Output is correct
20 Correct 180 ms 299000 KB Output is correct
21 Correct 176 ms 297080 KB Output is correct
22 Correct 195 ms 297720 KB Output is correct
23 Correct 185 ms 298360 KB Output is correct
24 Correct 184 ms 299000 KB Output is correct
25 Correct 1090 ms 366328 KB Output is correct
26 Correct 2103 ms 431608 KB Output is correct
27 Correct 3249 ms 495480 KB Output is correct
28 Runtime error 2895 ms 524292 KB Execution killed with signal 9 (could be triggered by violating memory limits)
29 Halted 0 ms 0 KB -