Submission #199907

# Submission time Handle Problem Language Result Execution time Memory
199907 2020-02-03T23:13:15 Z mdn2002 Klasika (COCI20_klasika) C++14
110 / 110
4578 ms 470700 KB
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,a[200005],k,trie[4000000][3],ans;
int en[200005],ot[200005],tmm;
vector<int>gr[200005],aq,bq;
vector<string>sq;
set<int>tim[4000000];
void dfs(int x,int p)
{
    en[x]=++tmm;
    for(int i=0; i<gr[x].size(); i++)
    {
        int u=gr[x][i];
        if(u==p)continue;
        dfs(u,x);
    }
    ot[x]=tmm;
}
string to(long long x)
{
    string s;
    while(x)
    {
        s.push_back('0'+(x%2));
        x/=2;
    }
    while(s.size()!=30)s.push_back('0');
    reverse(s.begin(),s.end());
    return s;
}
void ad(string s,int st)
{
    int nod=0;
    for(int i=0; i<s.size(); i++)
    {
        int x=s[i]-'0';
        if(trie[nod][x]==0)trie[nod][x]=++k;
        nod=trie[nod][x];
        tim[nod].insert(st);
    }
}
void qu(string s,int z,int x,int st,int fn)
{
    if(s[z]=='1')
    {
        int txo=trie[x][0];
        int too=1e9;
        if(tim[txo].lower_bound(st)!=tim[txo].end())too=*tim[txo].lower_bound(st);
        if(trie[x][0]!=0&&st<=too&&too<=fn)
        {
            ans*=2;
            ans++;
            qu(s,z+1,trie[x][0],st,fn);
            return;
        }
        else if(trie[x][1]!=0)
        {
            ans*=2;
            qu(s,z+1,trie[x][1],st,fn);
        }
    }
    else
    {
        int tx1=trie[x][1];
        int to1=1e9;
        if(tim[tx1].lower_bound(st)!=tim[tx1].end())to1=*tim[tx1].lower_bound(st);
        if(trie[x][1]!=0&&st<=to1&&to1<=fn)
        {
            ans*=2;
            ans++;
            qu(s,z+1,trie[x][1],st,fn);
        }
        else if(trie[x][0]!=0)
        {
            ans*=2;
            qu(s,z+1,trie[x][0],st,fn);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("gpsduel.in","r",stdin);
    //freopen("gpsduel.out","w",stdout);
    cin>>n;
    int num=1;
    for(int i=0; i<n; i++)
    {
        string s;
        long long x,y;
        cin>>s>>x>>y;
        sq.push_back(s);
        aq.push_back(x);
        bq.push_back(y);
        if(s=="Add")
        {
            num++;
            gr[x].push_back(num);
        }
    }
    dfs(1,0);
    num=1;
    string ss=to(0);
    ad(ss,1);
    for(int i=0; i<n; i++)
    {
        string s=sq[i];
        long long x=aq[i],y=bq[i];
        if(s=="Add")
        {
            num++;
            a[num]=a[x]^y;
            string st=to(a[num]);
            ad(st,en[num]);
        }
        else
        {
            ans=0;
            long long b=a[x];
            qu(to(b),0,0,en[y],ot[y]);
            cout<<ans<<endl;
        }
    }
}

Compilation message

klasika.cpp: In function 'void dfs(int, int)':
klasika.cpp:12:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<gr[x].size(); i++)
                  ~^~~~~~~~~~~~~
klasika.cpp: In function 'void ad(std::__cxx11::string, int)':
klasika.cpp:35:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<s.size(); i++)
                  ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 133 ms 193020 KB Output is correct
2 Correct 134 ms 193016 KB Output is correct
3 Correct 154 ms 193144 KB Output is correct
4 Correct 131 ms 193144 KB Output is correct
5 Correct 129 ms 193016 KB Output is correct
6 Correct 130 ms 193016 KB Output is correct
7 Correct 128 ms 193144 KB Output is correct
8 Correct 132 ms 193144 KB Output is correct
9 Correct 128 ms 193016 KB Output is correct
10 Correct 129 ms 193016 KB Output is correct
11 Correct 132 ms 193144 KB Output is correct
12 Correct 131 ms 193144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 193020 KB Output is correct
2 Correct 134 ms 193016 KB Output is correct
3 Correct 154 ms 193144 KB Output is correct
4 Correct 131 ms 193144 KB Output is correct
5 Correct 129 ms 193016 KB Output is correct
6 Correct 130 ms 193016 KB Output is correct
7 Correct 128 ms 193144 KB Output is correct
8 Correct 132 ms 193144 KB Output is correct
9 Correct 128 ms 193016 KB Output is correct
10 Correct 129 ms 193016 KB Output is correct
11 Correct 132 ms 193144 KB Output is correct
12 Correct 131 ms 193144 KB Output is correct
13 Correct 141 ms 193784 KB Output is correct
14 Correct 143 ms 194424 KB Output is correct
15 Correct 136 ms 195192 KB Output is correct
16 Correct 139 ms 195832 KB Output is correct
17 Correct 142 ms 193656 KB Output is correct
18 Correct 145 ms 194424 KB Output is correct
19 Correct 143 ms 195064 KB Output is correct
20 Correct 142 ms 195704 KB Output is correct
21 Correct 140 ms 193656 KB Output is correct
22 Correct 142 ms 194552 KB Output is correct
23 Correct 148 ms 195048 KB Output is correct
24 Correct 141 ms 195704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2193 ms 270008 KB Output is correct
2 Correct 2948 ms 336120 KB Output is correct
3 Correct 3640 ms 401176 KB Output is correct
4 Correct 4303 ms 466900 KB Output is correct
5 Correct 2251 ms 267404 KB Output is correct
6 Correct 2974 ms 331412 KB Output is correct
7 Correct 3675 ms 394100 KB Output is correct
8 Correct 4182 ms 457240 KB Output is correct
9 Correct 2224 ms 267396 KB Output is correct
10 Correct 2988 ms 332716 KB Output is correct
11 Correct 3663 ms 396188 KB Output is correct
12 Correct 4145 ms 459316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 193020 KB Output is correct
2 Correct 134 ms 193016 KB Output is correct
3 Correct 154 ms 193144 KB Output is correct
4 Correct 131 ms 193144 KB Output is correct
5 Correct 129 ms 193016 KB Output is correct
6 Correct 130 ms 193016 KB Output is correct
7 Correct 128 ms 193144 KB Output is correct
8 Correct 132 ms 193144 KB Output is correct
9 Correct 128 ms 193016 KB Output is correct
10 Correct 129 ms 193016 KB Output is correct
11 Correct 132 ms 193144 KB Output is correct
12 Correct 131 ms 193144 KB Output is correct
13 Correct 141 ms 193784 KB Output is correct
14 Correct 143 ms 194424 KB Output is correct
15 Correct 136 ms 195192 KB Output is correct
16 Correct 139 ms 195832 KB Output is correct
17 Correct 142 ms 193656 KB Output is correct
18 Correct 145 ms 194424 KB Output is correct
19 Correct 143 ms 195064 KB Output is correct
20 Correct 142 ms 195704 KB Output is correct
21 Correct 140 ms 193656 KB Output is correct
22 Correct 142 ms 194552 KB Output is correct
23 Correct 148 ms 195048 KB Output is correct
24 Correct 141 ms 195704 KB Output is correct
25 Correct 2193 ms 270008 KB Output is correct
26 Correct 2948 ms 336120 KB Output is correct
27 Correct 3640 ms 401176 KB Output is correct
28 Correct 4303 ms 466900 KB Output is correct
29 Correct 2251 ms 267404 KB Output is correct
30 Correct 2974 ms 331412 KB Output is correct
31 Correct 3675 ms 394100 KB Output is correct
32 Correct 4182 ms 457240 KB Output is correct
33 Correct 2224 ms 267396 KB Output is correct
34 Correct 2988 ms 332716 KB Output is correct
35 Correct 3663 ms 396188 KB Output is correct
36 Correct 4145 ms 459316 KB Output is correct
37 Correct 2962 ms 270204 KB Output is correct
38 Correct 3668 ms 335916 KB Output is correct
39 Correct 4117 ms 402552 KB Output is correct
40 Correct 4419 ms 470700 KB Output is correct
41 Correct 2986 ms 270908 KB Output is correct
42 Correct 3721 ms 334736 KB Output is correct
43 Correct 4128 ms 397832 KB Output is correct
44 Correct 4372 ms 460720 KB Output is correct
45 Correct 3116 ms 270728 KB Output is correct
46 Correct 3867 ms 336092 KB Output is correct
47 Correct 4296 ms 399140 KB Output is correct
48 Correct 4578 ms 463228 KB Output is correct