답안 #940450

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940450 2024-03-07T09:30:20 Z User0069 Klasika (COCI20_klasika) C++17
33 / 110
773 ms 524288 KB
#include<bits/stdc++.h>
#define taskname ""
#define el '\n'
#define fi first
#define sc second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
//#define int ll
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
const int maxn=2e5+1;
const int INF=1e9;
vector<int> adj[maxn];
int q,n,in[maxn],out[maxn],a[maxn],b[maxn],v[maxn],cur;
string s[maxn];
struct node
{
    node* child[2];
    node()
    {
        child[1]=child[0]=NULL;
    }
};
void add(node* root, int x)
{
    node* cur=root;
    for(int i=30;i>=0;i--)
    {
        int c=(x>>i)&1;
        if(cur->child[c]==NULL) cur->child[c]=new node();
        cur=cur->child[c];
    }
}
int get(node* root, int x)
{
    node* cur =root;
    if(cur->child[1]==NULL&&cur->child[0]==NULL) return 0;
    int ans=0;
    for(int i=30;i>=0;i--)
    {
        int c=(x>>i)&1;
        if(cur->child[1^c]!=NULL) cur=cur->child[1^c],ans+=(1<<i);
        else cur=cur->child[c];
    }
    return ans;
}
node* ST[4*maxn];
int get(int id,int cl,int cr,int l,int r,int val)
{
    if(cl>r||cr<l) return 0;
    if(cl>=l&&cr<=r) return get(ST[id],val);
    int mid=(cl+cr)/2;
    return max(get(2*id,cl,mid,l,r,val),get(2*id+1,mid+1,cr,l,r,val));
}
void update(int id,int cl,int cr,int pos,int val)
{
    if(cl>pos||cr<pos) return;
    add(ST[id],val);
    if(cl==cr) return;
    int mid=(cl+cr)/2;
    if(pos<=mid) update(2*id,cl,mid,pos,val);
    else update(2*id+1,mid+1,cr,pos,val);
}
void dfs(int x)
{
    in[x]=++cur;
    for(int y:adj[x])
    {
        dfs(y);
    }
    out[x]=cur;
}
signed main()
{
    if (fopen(taskname".INP","r"))
    {
        freopen(taskname".INP","r",stdin);
        freopen(taskname".OUT","w",stdout);
    }
    Faster
    cin>>q;
    for(int i=1;i<=4*q;i++) ST[i]=new node();
    n=1;
    for(int i=1;i<=q;i++)
    {
        cin>>s[i]>>a[i]>>b[i];
        if(s[i]=="Add")
        {
            adj[a[i]].push_back(++n);
            v[n]=b[i]^v[a[i]];
        }
    }
    dfs(1);
    cur=1;
    update(1,1,n,1,0);
    for(int i=1;i<=q;i++)
    {
        if(s[i]=="Add")
        {
            ++cur;
            update(1,1,n,in[cur],v[cur]);
        }
        else
        {
            cout<<get(1,1,n,in[b[i]],out[b[i]],v[a[i]])<<"\n";
        }
    }
//    for(int i=1;i<=n;i++) cout<<v[i]<<" ";
}

Compilation message

klasika.cpp: In function 'int main()':
klasika.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(taskname".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
klasika.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(taskname".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 17504 KB Output is correct
2 Correct 4 ms 17756 KB Output is correct
3 Correct 5 ms 18008 KB Output is correct
4 Correct 4 ms 18460 KB Output is correct
5 Correct 4 ms 17496 KB Output is correct
6 Correct 4 ms 17756 KB Output is correct
7 Correct 5 ms 18012 KB Output is correct
8 Correct 5 ms 18268 KB Output is correct
9 Correct 4 ms 17500 KB Output is correct
10 Correct 4 ms 17756 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 5 ms 18268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 17504 KB Output is correct
2 Correct 4 ms 17756 KB Output is correct
3 Correct 5 ms 18008 KB Output is correct
4 Correct 4 ms 18460 KB Output is correct
5 Correct 4 ms 17496 KB Output is correct
6 Correct 4 ms 17756 KB Output is correct
7 Correct 5 ms 18012 KB Output is correct
8 Correct 5 ms 18268 KB Output is correct
9 Correct 4 ms 17500 KB Output is correct
10 Correct 4 ms 17756 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 5 ms 18268 KB Output is correct
13 Correct 11 ms 21084 KB Output is correct
14 Correct 12 ms 24756 KB Output is correct
15 Correct 17 ms 29076 KB Output is correct
16 Correct 20 ms 32860 KB Output is correct
17 Correct 10 ms 20720 KB Output is correct
18 Correct 12 ms 24668 KB Output is correct
19 Correct 15 ms 28764 KB Output is correct
20 Correct 19 ms 32604 KB Output is correct
21 Correct 9 ms 20828 KB Output is correct
22 Correct 12 ms 24708 KB Output is correct
23 Correct 16 ms 29064 KB Output is correct
24 Correct 19 ms 32604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 773 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 17504 KB Output is correct
2 Correct 4 ms 17756 KB Output is correct
3 Correct 5 ms 18008 KB Output is correct
4 Correct 4 ms 18460 KB Output is correct
5 Correct 4 ms 17496 KB Output is correct
6 Correct 4 ms 17756 KB Output is correct
7 Correct 5 ms 18012 KB Output is correct
8 Correct 5 ms 18268 KB Output is correct
9 Correct 4 ms 17500 KB Output is correct
10 Correct 4 ms 17756 KB Output is correct
11 Correct 4 ms 18012 KB Output is correct
12 Correct 5 ms 18268 KB Output is correct
13 Correct 11 ms 21084 KB Output is correct
14 Correct 12 ms 24756 KB Output is correct
15 Correct 17 ms 29076 KB Output is correct
16 Correct 20 ms 32860 KB Output is correct
17 Correct 10 ms 20720 KB Output is correct
18 Correct 12 ms 24668 KB Output is correct
19 Correct 15 ms 28764 KB Output is correct
20 Correct 19 ms 32604 KB Output is correct
21 Correct 9 ms 20828 KB Output is correct
22 Correct 12 ms 24708 KB Output is correct
23 Correct 16 ms 29064 KB Output is correct
24 Correct 19 ms 32604 KB Output is correct
25 Runtime error 773 ms 524288 KB Execution killed with signal 9
26 Halted 0 ms 0 KB -