Submission #832984

# Submission time Handle Problem Language Result Execution time Memory
832984 2023-08-21T17:59:37 Z damwuan Klasika (COCI20_klasika) C++17
110 / 110
1384 ms 213980 KB



#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define bit(n,i) ((n>>i)&1)
#define all(x) x.begin(),x.end()
//#pragma GCC optimize("O2,unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,ssse3,sse4,popcnt")
//#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef double ld;
typedef pair<ld,ld> pdd;
typedef pair<ll,ll> pll;
const ll maxn=2e5+5;
const ll offset=1e9;
const ll block_sz=317;
const ll inf=1e9;
const ll mod=1e9+7;
int n;
struct TrieNode
{
    TrieNode* child[2];
    int cnt;
    TrieNode()
    {
        child[0]=child[1]=nullptr;
        cnt=inf;
    }
};
TrieNode* root[maxn];
void Update(TrieNode* r, int u,int Time)
{
    TrieNode* cur=r;
    for2(i,30,0)
    {
        bool nxt=(u>>i)&1;
        if (cur->child[nxt]==nullptr)
        {
            cur->child[nxt]=new TrieNode;
        }
        cur=cur->child[nxt];
        cur->cnt=min(cur->cnt,Time);
    }
}
int Get(TrieNode* r, int u,int Time)
{
    int ans=0;
    TrieNode* cur=r;
    for2(i,30,0)
    {
        bool nxt=((u>>i)&1)^1;
        //cerr<< nxt<<'\n';
        if (cur->child[nxt]!=nullptr && cur->child[nxt]->cnt<=Time)
        {
            cur=cur->child[nxt];
            ans+=(1<<i);
        }
        else
        //if (cur->child[nxt|1]!=nullptr)
        cur=cur->child[nxt^1];
        //else cout << "wtf\n";
    }
    return ans;
}
void Del(TrieNode* &r)
{
    if (r->child[0])
    {
        Del(r->child[0]);
    }
    if (r->child[1])
    {
        Del(r->child[1]);
    }
    delete r;
}
int q,id[maxn];
string type;
int pre[maxn],ans[maxn];
vector<int> adj[maxn],L[maxn];
vector<pii> qr[maxn];
void dfs(int u)
{
//    cerr<< u<<' '<<pre[u]<<'\n';
    L[u].pb(u);
    Update(root[u],pre[u],id[u]);
    for(int v: adj[u])
    {
//        cerr<< v<<" asd\n";
        dfs(v);
    }
    for(int v: adj[u])
    {
        if (L[v].size()>L[u].size())
        {
            L[u].swap(L[v]);
            swap(root[u],root[v]);
        }
        for(int a:L[v])
        {
            L[u].pb(a);
            Update(root[u],pre[a],id[a]);
        }
        L[v].clear();
        Del(root[v]);
    }
    //cerr<< u<< ' '<<L[u].size()<<" wtf\n";
    //...
    for(auto x: qr[u])
    {
        //cerr<< u<<' '<<x.se<<' '<<x.fi<<' '<<L[u].size()<<'\n';
        ans[x.se]=Get(root[u],x.fi,x.se);
    }
}
void sol()
{
    cin >> q;
    n=1;
    for1(i,1,q)
    {
        ans[i]=-1;
        int a,b;cin>> type>>a>>b;
        if (type[0]=='A')
        {
            adj[a].pb(++n);
            pre[n]=pre[a]^b;
            id[n]=i;
        }
        else
        {
            qr[b].pb({pre[a],i});
        }
    }
    for1(i,1,n) root[i]=new TrieNode;
//    cerr<< "kk\n";
    dfs(1);
    for1(i,1,q) if (ans[i]!=-1) cout << ans[i]<<'\n';
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("GROUPDIV.inp","r",stdin);
//    freopen("GROUPDIV.out","w",stdout);

    int t=1;//cin >> t;
    while (t--)
    {
        sol();
    }
}







# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14460 KB Output is correct
3 Correct 8 ms 14548 KB Output is correct
4 Correct 8 ms 14564 KB Output is correct
5 Correct 10 ms 14420 KB Output is correct
6 Correct 9 ms 14620 KB Output is correct
7 Correct 8 ms 14548 KB Output is correct
8 Correct 9 ms 14548 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 7 ms 14548 KB Output is correct
11 Correct 7 ms 14548 KB Output is correct
12 Correct 7 ms 14548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14460 KB Output is correct
3 Correct 8 ms 14548 KB Output is correct
4 Correct 8 ms 14564 KB Output is correct
5 Correct 10 ms 14420 KB Output is correct
6 Correct 9 ms 14620 KB Output is correct
7 Correct 8 ms 14548 KB Output is correct
8 Correct 9 ms 14548 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 7 ms 14548 KB Output is correct
11 Correct 7 ms 14548 KB Output is correct
12 Correct 7 ms 14548 KB Output is correct
13 Correct 11 ms 14932 KB Output is correct
14 Correct 9 ms 15476 KB Output is correct
15 Correct 10 ms 15956 KB Output is correct
16 Correct 12 ms 16340 KB Output is correct
17 Correct 9 ms 14896 KB Output is correct
18 Correct 10 ms 15104 KB Output is correct
19 Correct 14 ms 15684 KB Output is correct
20 Correct 12 ms 15828 KB Output is correct
21 Correct 9 ms 14804 KB Output is correct
22 Correct 10 ms 15060 KB Output is correct
23 Correct 14 ms 15384 KB Output is correct
24 Correct 11 ms 15652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 227 ms 66508 KB Output is correct
2 Correct 326 ms 114704 KB Output is correct
3 Correct 429 ms 161712 KB Output is correct
4 Correct 487 ms 209192 KB Output is correct
5 Correct 351 ms 45632 KB Output is correct
6 Correct 668 ms 74228 KB Output is correct
7 Correct 1000 ms 93876 KB Output is correct
8 Correct 1247 ms 118680 KB Output is correct
9 Correct 277 ms 46924 KB Output is correct
10 Correct 402 ms 72748 KB Output is correct
11 Correct 518 ms 99164 KB Output is correct
12 Correct 581 ms 123640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14420 KB Output is correct
2 Correct 7 ms 14460 KB Output is correct
3 Correct 8 ms 14548 KB Output is correct
4 Correct 8 ms 14564 KB Output is correct
5 Correct 10 ms 14420 KB Output is correct
6 Correct 9 ms 14620 KB Output is correct
7 Correct 8 ms 14548 KB Output is correct
8 Correct 9 ms 14548 KB Output is correct
9 Correct 7 ms 14420 KB Output is correct
10 Correct 7 ms 14548 KB Output is correct
11 Correct 7 ms 14548 KB Output is correct
12 Correct 7 ms 14548 KB Output is correct
13 Correct 11 ms 14932 KB Output is correct
14 Correct 9 ms 15476 KB Output is correct
15 Correct 10 ms 15956 KB Output is correct
16 Correct 12 ms 16340 KB Output is correct
17 Correct 9 ms 14896 KB Output is correct
18 Correct 10 ms 15104 KB Output is correct
19 Correct 14 ms 15684 KB Output is correct
20 Correct 12 ms 15828 KB Output is correct
21 Correct 9 ms 14804 KB Output is correct
22 Correct 10 ms 15060 KB Output is correct
23 Correct 14 ms 15384 KB Output is correct
24 Correct 11 ms 15652 KB Output is correct
25 Correct 227 ms 66508 KB Output is correct
26 Correct 326 ms 114704 KB Output is correct
27 Correct 429 ms 161712 KB Output is correct
28 Correct 487 ms 209192 KB Output is correct
29 Correct 351 ms 45632 KB Output is correct
30 Correct 668 ms 74228 KB Output is correct
31 Correct 1000 ms 93876 KB Output is correct
32 Correct 1247 ms 118680 KB Output is correct
33 Correct 277 ms 46924 KB Output is correct
34 Correct 402 ms 72748 KB Output is correct
35 Correct 518 ms 99164 KB Output is correct
36 Correct 581 ms 123640 KB Output is correct
37 Correct 273 ms 70896 KB Output is correct
38 Correct 349 ms 118772 KB Output is correct
39 Correct 423 ms 167200 KB Output is correct
40 Correct 499 ms 213980 KB Output is correct
41 Correct 333 ms 53020 KB Output is correct
42 Correct 644 ms 78924 KB Output is correct
43 Correct 864 ms 94276 KB Output is correct
44 Correct 1384 ms 129120 KB Output is correct
45 Correct 205 ms 47980 KB Output is correct
46 Correct 326 ms 73872 KB Output is correct
47 Correct 478 ms 99420 KB Output is correct
48 Correct 541 ms 124264 KB Output is correct