Submission #844591

# Submission time Handle Problem Language Result Execution time Memory
844591 2023-09-05T14:26:23 Z vjudge1 Klasika (COCI20_klasika) C++17
0 / 110
359 ms 60332 KB
#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define int long long
using namespace std;

const int inf = 2e18 + 5;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;

vector<pair<int, int> > adj[N];
vector<int> valxor(N);

struct node{
  int to[2];
  int cnt;
  node(){
    to[0] = to[1] = -1;
    cnt = 0;
  }
};

vector<node> t;

void add(int x){
  int v = 0;
  for(int i = 29; i >= 0; i--){
    int c = ((x & (1 << i)) > 0);
    if(!t[v].to[c] != -1){
        t[v].to[c] = t.size();
        t.pb(node());
        t[v].cnt++;
    }
    v = t[v].to[c];
  }
  t[v].cnt++;
}

int solve(int v, int k, int tp, int val){
  if(tp < 0) return val;

  int mask = (k & (1 << tp) > 0 ? 0 : 1);

  if(t[v].to[mask] != -1){
    return solve(t[v].to[mask], k, tp-1, val + (1 << tp));
  }
  else{
    return solve(t[v].to[mask^1], k, tp-1, val);
  }
}

int32_t main(){
  //freopen("in.txt","r", stdin);
  t.pb(node());
  int q;
  cin>>q;
  int ncnt = 1;
  valxor[1] = 0;

  while(q--){
    string s;
    cin>>s;

    if(s == "Add"){
        int x, y;
        cin>>x>>y;
        ncnt++;
        adj[ncnt].pb({x, y});
        adj[x].pb({ncnt, y});
        valxor[ncnt] = (valxor[x] ^ y);
        add(valxor[ncnt]);
    }
    else{
        int a, b; // b == 1
        cin>>a>>b;
        int ans = 0, add = valxor[a];
        ans = solve(0, valxor[a], 29, 0);
        cout<<ans<<endl;
    }
  }
  return 0;
}

Compilation message

klasika.cpp: In function 'void add(long long int)':
klasika.cpp:29:20: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
   29 |     if(!t[v].to[c] != -1){
      |                    ^~
klasika.cpp:29:8: note: add parentheses around left hand side expression to silence this warning
   29 |     if(!t[v].to[c] != -1){
      |        ^~~~~~~~~~~
      |        (          )
klasika.cpp:29:20: warning: comparison of constant '-1' with boolean expression is always true [-Wbool-compare]
   29 |     if(!t[v].to[c] != -1){
      |        ~~~~~~~~~~~~^~~~~
klasika.cpp: In function 'long long int solve(long long int, long long int, long long int, long long int)':
klasika.cpp:42:29: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   42 |   int mask = (k & (1 << tp) > 0 ? 0 : 1);
      |                   ~~~~~~~~~~^~~
klasika.cpp: In function 'int32_t main()':
klasika.cpp:76:22: warning: unused variable 'add' [-Wunused-variable]
   76 |         int ans = 0, add = valxor[a];
      |                      ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6744 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 359 ms 60332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 6744 KB Output isn't correct
2 Halted 0 ms 0 KB -