# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
201095 |
2020-02-09T10:39:48 Z |
mraron |
Klasika (COCI20_klasika) |
C++14 |
|
1915 ms |
524292 KB |
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair
#ifndef ONLINE_JUDGE
# define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
# define LOG(x) ((void)0)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double PI=3.1415926535897932384626433832795;
const ll INF = 1LL<<62;
const ll MINF = -1LL<<62;
template<typename T> T getint() {
T val=0;
char c;
bool neg=false;
while((c=gc()) && !(c>='0' && c<='9')) {
neg|=c=='-';
}
do {
val=(val*10)+c-'0';
} while((c=gc()) && (c>='0' && c<='9'));
return val*(neg?-1:1);
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)
int q;
struct op {
int typ,a,b;
};
const int MAXN=200001;
int n=1;
vector<op> lst;
vector<pair<int,int>> adj[MAXN];
int sz[MAXN], par[MAXN], d[MAXN];
void dfs_pre(int x) {
sz[x]=1;
for(auto i:adj[x]) {
if(!sz[i.xx]) {
par[i.xx]=x;
d[i.xx]=i.yy^d[x];
dfs_pre(i.xx);
sz[x]+=sz[i.xx];
}
}
}
int hld_top[MAXN], hld_id[MAXN], hld_pos[MAXN], pos=0, id=1;
void dfs_hld(int x) {
// cerr<<x<<" "<<pos<<"\n";
hld_id[x]=id;
hld_pos[x]=pos++;
if(!hld_top[hld_id[x]]) {
hld_top[hld_id[x]]=x;
}
int best=0;
for(auto i:adj[x]) {
if(par[x]==i.xx) continue ;
if(!best || sz[best]<sz[i.xx]) best=i.xx;
}
if(best>0) dfs_hld(best);
for(auto i:adj[x]) {
if(par[x]!=i.xx && i.xx!=best) {
id++;
dfs_hld(i.xx);
}
}
}
struct node {
node* sub[2];
node() {
sub[0]=sub[1]=NULL;
}
};
void insert(node* root, int num) {
for(int i=30;i>=0;i--) {
int c=(num&(1<<i))!=0;
if(root->sub[c]==NULL) {
root->sub[c]=new node;
}
root=root->sub[c];
}
}
int mx(node *root, int with) {
if(root==NULL) return 0;
if(root->sub[0]==NULL && root->sub[1]==NULL) return 0;
int ans=0;
for(int i=30;i>=0;i--) {
int c=(with&(1<<i))!=0;
if(root->sub[1-c]!=NULL) {
ans|=1<<i;
root=root->sub[1-c];
}else {
root=root->sub[c];
}
}
return ans;
}
node* tree[8*MAXN];
void add(int ind, int L, int R, int i, int j, int mit) {
//cerr<<ind<<" "<<L<<" "<<R<<" "<<i<<" "<<j<<" "<<mit<<"add\n"<<flush;
if(R<i || j<L) return ;
if(i<=L && R<=j) {
if(tree[ind]==NULL) tree[ind]=new node;
insert(tree[ind], mit);
return ;
}
add(2*ind, L, (L+R)/2, i, j, mit);
add(2*ind+1, (L+R)/2+1, R, i, j, mit);
}
int mx(int ind, int L, int R, int i, int with) {
//cerr<<ind<<" "<<L<<" "<<R<<" "<<i<<" "<<i<<" "<<with<<"mx\n"<<flush;
if(R<i || i<L) return 0;
int ans=mx(tree[ind], with);
if(L!=R) ans=max(ans, max(mx(2*ind, L, (L+R)/2, i, with), mx(2*ind+1, (L+R)/2+1, R, i, with)));
return ans;
}
void add(int root, int dd) {
while(root>0) {
int blk=hld_id[root];
int tp=hld_top[blk];
add(1,0,pos-1,hld_pos[tp],hld_pos[root],dd);
root=par[tp];
}
}
int query(int a, int b) {
int base=d[a];
//cerr<<base<<"\n";
//cerr<<hld_pos[b]<<"\n";
return mx(1,0,pos-1,hld_pos[b],base);
}
int main() {
IO;
cin>>q;
lst.resize(q);
for(int i=0;i<q;++i) {
string t;
cin>>t;
lst[i].typ=(t=="Add"?0:1);
cin>>lst[i].a>>lst[i].b;
if(lst[i].typ==0) {
adj[lst[i].a].push_back({n+1, lst[i].b});
adj[n+1].push_back({lst[i].a, lst[i].b});
lst[i].a=n+1;
n++;
}
}
dfs_pre(1);
dfs_hld(1);
add(1,0,pos-1,0,0,0);
for(auto i:lst) {
if(i.typ==0) {
//cerr<<"typ0\n";
add(i.a, d[i.a]);
}else {
//cerr<<"typ1\n";
cout<<query(i.a,i.b)<<"\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
5240 KB |
Output is correct |
2 |
Correct |
9 ms |
5240 KB |
Output is correct |
3 |
Correct |
10 ms |
5496 KB |
Output is correct |
4 |
Correct |
8 ms |
5624 KB |
Output is correct |
5 |
Correct |
8 ms |
5240 KB |
Output is correct |
6 |
Correct |
8 ms |
5244 KB |
Output is correct |
7 |
Correct |
8 ms |
5372 KB |
Output is correct |
8 |
Correct |
10 ms |
5624 KB |
Output is correct |
9 |
Correct |
8 ms |
5240 KB |
Output is correct |
10 |
Correct |
9 ms |
5368 KB |
Output is correct |
11 |
Correct |
9 ms |
5496 KB |
Output is correct |
12 |
Correct |
9 ms |
5624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
5240 KB |
Output is correct |
2 |
Correct |
9 ms |
5240 KB |
Output is correct |
3 |
Correct |
10 ms |
5496 KB |
Output is correct |
4 |
Correct |
8 ms |
5624 KB |
Output is correct |
5 |
Correct |
8 ms |
5240 KB |
Output is correct |
6 |
Correct |
8 ms |
5244 KB |
Output is correct |
7 |
Correct |
8 ms |
5372 KB |
Output is correct |
8 |
Correct |
10 ms |
5624 KB |
Output is correct |
9 |
Correct |
8 ms |
5240 KB |
Output is correct |
10 |
Correct |
9 ms |
5368 KB |
Output is correct |
11 |
Correct |
9 ms |
5496 KB |
Output is correct |
12 |
Correct |
9 ms |
5624 KB |
Output is correct |
13 |
Correct |
12 ms |
6776 KB |
Output is correct |
14 |
Correct |
17 ms |
8444 KB |
Output is correct |
15 |
Correct |
17 ms |
10360 KB |
Output is correct |
16 |
Correct |
20 ms |
12152 KB |
Output is correct |
17 |
Correct |
13 ms |
6520 KB |
Output is correct |
18 |
Correct |
14 ms |
8056 KB |
Output is correct |
19 |
Correct |
16 ms |
10068 KB |
Output is correct |
20 |
Correct |
21 ms |
12128 KB |
Output is correct |
21 |
Correct |
14 ms |
7032 KB |
Output is correct |
22 |
Correct |
15 ms |
8988 KB |
Output is correct |
23 |
Correct |
68 ms |
11128 KB |
Output is correct |
24 |
Correct |
29 ms |
12920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1543 ms |
239664 KB |
Output is correct |
2 |
Correct |
1915 ms |
488964 KB |
Output is correct |
3 |
Runtime error |
1501 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
5240 KB |
Output is correct |
2 |
Correct |
9 ms |
5240 KB |
Output is correct |
3 |
Correct |
10 ms |
5496 KB |
Output is correct |
4 |
Correct |
8 ms |
5624 KB |
Output is correct |
5 |
Correct |
8 ms |
5240 KB |
Output is correct |
6 |
Correct |
8 ms |
5244 KB |
Output is correct |
7 |
Correct |
8 ms |
5372 KB |
Output is correct |
8 |
Correct |
10 ms |
5624 KB |
Output is correct |
9 |
Correct |
8 ms |
5240 KB |
Output is correct |
10 |
Correct |
9 ms |
5368 KB |
Output is correct |
11 |
Correct |
9 ms |
5496 KB |
Output is correct |
12 |
Correct |
9 ms |
5624 KB |
Output is correct |
13 |
Correct |
12 ms |
6776 KB |
Output is correct |
14 |
Correct |
17 ms |
8444 KB |
Output is correct |
15 |
Correct |
17 ms |
10360 KB |
Output is correct |
16 |
Correct |
20 ms |
12152 KB |
Output is correct |
17 |
Correct |
13 ms |
6520 KB |
Output is correct |
18 |
Correct |
14 ms |
8056 KB |
Output is correct |
19 |
Correct |
16 ms |
10068 KB |
Output is correct |
20 |
Correct |
21 ms |
12128 KB |
Output is correct |
21 |
Correct |
14 ms |
7032 KB |
Output is correct |
22 |
Correct |
15 ms |
8988 KB |
Output is correct |
23 |
Correct |
68 ms |
11128 KB |
Output is correct |
24 |
Correct |
29 ms |
12920 KB |
Output is correct |
25 |
Correct |
1543 ms |
239664 KB |
Output is correct |
26 |
Correct |
1915 ms |
488964 KB |
Output is correct |
27 |
Runtime error |
1501 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
28 |
Halted |
0 ms |
0 KB |
- |