답안 #1113977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113977 2024-11-18T03:27:50 Z 12345678 Klasika (COCI20_klasika) C++17
33 / 110
948 ms 524288 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=2e5+5;

int q, x, y, dp[nx], cur=1, t[nx], res[nx], sz[nx];
string s;
vector<int> d[nx];
vector<pair<int, int>> qrs[nx];

struct node
{
    int mn;
    node *l, *r;
    node(): mn(1e9), l(0), r(0){}
};
typedef node* pnode;
pnode rt[nx];

void add(int x, int u)
{
    if (!rt[x]) rt[x]=new node(), rt[x]->mn=0;
    pnode c=rt[x];
    for (int i=30; i>=0; i--)
    {
        if (dp[u]&(1<<i))
        {
            if (!c->r) c->r=new node();
            c=c->r;
            c->mn=min(c->mn, t[u]);
        }
        else
        {
            if (!c->l) c->l=new node();
            c=c->l;
            c->mn=min(c->mn, t[u]);
        }
    }
}

void dfsadd(int u, int p)
{
    add(p, u);
    for (auto v:d[u]) dfsadd(v, p);
}

void solve(int u)
{
    sz[u]=1;
    pair<int, int> hv;
    for (auto v:d[u]) solve(v), sz[u]+=sz[v], hv=max(hv, {sz[v], v});
    if (hv.second) swap(rt[u], rt[hv.second]);
    for (auto v:d[u]) if (v!=hv.second) dfsadd(v, u);
    add(u, u);
    for (auto [x, idx]:qrs[u])
    {
        int ans=0;
        pnode cur=rt[u];
        for (int i=0; i<=30; i++)
        {
            if (dp[x]&(1<<(30-i)))
            {
                if (cur->l&&cur->l->mn<=idx) ans+=(1<<(30-i)), cur=cur->l;
                else cur=cur->r; 
            }
            else
            {
                if (cur->r&&cur->r->mn<=idx) ans+=(1<<(30-i)), cur=cur->r;
                else cur=cur->l;
            }
        }
        res[idx]=ans;
    }
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>q;
    for (int i=1; i<=q; i++)
    {
        cin>>s>>x>>y;
        res[i]=-1;
        if (s[0]=='A') dp[++cur]=dp[x]^y, d[x].push_back(cur), t[cur]=i;
        else qrs[y].push_back({x, i});
    }
    solve(1);
    for (int i=1; i<=q; i++) if (res[i]!=-1) cout<<res[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9808 KB Output is correct
2 Correct 7 ms 9808 KB Output is correct
3 Correct 7 ms 9808 KB Output is correct
4 Correct 8 ms 9808 KB Output is correct
5 Correct 7 ms 9808 KB Output is correct
6 Correct 7 ms 9808 KB Output is correct
7 Correct 7 ms 9872 KB Output is correct
8 Correct 7 ms 10064 KB Output is correct
9 Correct 7 ms 9808 KB Output is correct
10 Correct 7 ms 9808 KB Output is correct
11 Correct 7 ms 10100 KB Output is correct
12 Correct 7 ms 10064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9808 KB Output is correct
2 Correct 7 ms 9808 KB Output is correct
3 Correct 7 ms 9808 KB Output is correct
4 Correct 8 ms 9808 KB Output is correct
5 Correct 7 ms 9808 KB Output is correct
6 Correct 7 ms 9808 KB Output is correct
7 Correct 7 ms 9872 KB Output is correct
8 Correct 7 ms 10064 KB Output is correct
9 Correct 7 ms 9808 KB Output is correct
10 Correct 7 ms 9808 KB Output is correct
11 Correct 7 ms 10100 KB Output is correct
12 Correct 7 ms 10064 KB Output is correct
13 Correct 8 ms 10064 KB Output is correct
14 Correct 8 ms 10576 KB Output is correct
15 Correct 10 ms 10832 KB Output is correct
16 Correct 9 ms 11088 KB Output is correct
17 Correct 10 ms 10832 KB Output is correct
18 Correct 11 ms 12024 KB Output is correct
19 Correct 13 ms 13136 KB Output is correct
20 Correct 14 ms 14160 KB Output is correct
21 Correct 13 ms 10576 KB Output is correct
22 Correct 10 ms 11264 KB Output is correct
23 Correct 10 ms 11856 KB Output is correct
24 Correct 12 ms 12696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 137 ms 41780 KB Output is correct
2 Correct 181 ms 64704 KB Output is correct
3 Correct 217 ms 85956 KB Output is correct
4 Correct 242 ms 107200 KB Output is correct
5 Correct 313 ms 151788 KB Output is correct
6 Correct 542 ms 295100 KB Output is correct
7 Correct 790 ms 434016 KB Output is correct
8 Runtime error 948 ms 524288 KB Execution killed with signal 9
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9808 KB Output is correct
2 Correct 7 ms 9808 KB Output is correct
3 Correct 7 ms 9808 KB Output is correct
4 Correct 8 ms 9808 KB Output is correct
5 Correct 7 ms 9808 KB Output is correct
6 Correct 7 ms 9808 KB Output is correct
7 Correct 7 ms 9872 KB Output is correct
8 Correct 7 ms 10064 KB Output is correct
9 Correct 7 ms 9808 KB Output is correct
10 Correct 7 ms 9808 KB Output is correct
11 Correct 7 ms 10100 KB Output is correct
12 Correct 7 ms 10064 KB Output is correct
13 Correct 8 ms 10064 KB Output is correct
14 Correct 8 ms 10576 KB Output is correct
15 Correct 10 ms 10832 KB Output is correct
16 Correct 9 ms 11088 KB Output is correct
17 Correct 10 ms 10832 KB Output is correct
18 Correct 11 ms 12024 KB Output is correct
19 Correct 13 ms 13136 KB Output is correct
20 Correct 14 ms 14160 KB Output is correct
21 Correct 13 ms 10576 KB Output is correct
22 Correct 10 ms 11264 KB Output is correct
23 Correct 10 ms 11856 KB Output is correct
24 Correct 12 ms 12696 KB Output is correct
25 Correct 137 ms 41780 KB Output is correct
26 Correct 181 ms 64704 KB Output is correct
27 Correct 217 ms 85956 KB Output is correct
28 Correct 242 ms 107200 KB Output is correct
29 Correct 313 ms 151788 KB Output is correct
30 Correct 542 ms 295100 KB Output is correct
31 Correct 790 ms 434016 KB Output is correct
32 Runtime error 948 ms 524288 KB Execution killed with signal 9
33 Halted 0 ms 0 KB -