Submission #1017875

# Submission time Handle Problem Language Result Execution time Memory
1017875 2024-07-09T10:57:45 Z vjudge1 Klasika (COCI20_klasika) C++17
33 / 110
5000 ms 509120 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) v.begin(), v.end()

const int M = 2e5 + 2, thres = 1732;

vector<int> nei[M],ver[M*30];
int nxt[M*30][2],val[M],st[M],en[M],sz,t,parr[M];
stack<int> stk;

void dfs(int u)
{
	st[u]=t++;
	for (int i:nei[u])
		dfs(i);
	en[u]=t;
	stk.push(u);
}

void add(int vl,int tm)
{
	int cur=0;
	for (int i=30;i>=0;i--)
	{
		int x=0;
		if ((1<<i)&vl)
			x=1;
		if (!nxt[cur][x])
			nxt[cur][x]=++sz;
		cur=nxt[cur][x];
		ver[cur].push_back(tm);
	}
}

int get(int vl,int s,int e)
{
	int cur=0,ans=0;
	for (int i=30;i>=0;i--)
	{
		int x=1;
		if ((1<<i)&vl)
			x=0;
		if (!nxt[cur][x])
			x=1-x;
		else if(lower_bound(all(ver[nxt[cur][x]]),s)==lower_bound(all(ver[nxt[cur][x]]),e))
			x=1-x;
		else
			ans+=(1<<i);
		cur=nxt[cur][x];
	}
	return ans;
}

void dfs1(int u,int vl,int &ans)
{
	ans=max(ans,val[u]^vl);
	for (int i:nei[u])
		dfs1(i,vl,ans);
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);
	int q;
	cin>>q;
	int nodes=2;
	vector<int> pen;
	while (q--)
	{
		string s;
		cin>>s;
		if (s=="Add")
		{
			int x,y;
			cin>>x>>y;
			val[nodes]=val[x]^y;
			pen.push_back(nodes);
			if (x<pen[0])
				parr[nodes]=x;
			else
				parr[nodes]=parr[x];
			nei[x].push_back(nodes++);
		}
		else
		{
			int a,b;
			cin>>a>>b;
			int ans=0;
			if (!pen.empty() && pen[0]<=b)
				dfs1(b,val[a],ans);
			else
			{
				if (nodes>thres)
					ans=get(val[a],st[b],en[b]);
				else
					ans=val[a];
				for (int i:pen)
				{
					if (parr[i]==b || (nodes>thres && st[parr[i]]>=st[b] && st[parr[i]]<en[b]))
						ans=max(ans,val[i]^val[a]);
				}
			}
			cout<<ans<<'\n';
		}
		if (pen.size()==thres)
		{
			for (int i=0;i<sz;i++)
				nxt[i][0]=nxt[i][1]=0,ver[i].clear();
			t=0;
			pen.clear();
			dfs(1);
			sz=0;
			while (!stk.empty())
				add(val[stk.top()],st[stk.top()]),stk.pop();
		}
	}
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 54 ms 147540 KB Output is correct
2 Correct 55 ms 147576 KB Output is correct
3 Correct 52 ms 147548 KB Output is correct
4 Correct 53 ms 147540 KB Output is correct
5 Correct 58 ms 147540 KB Output is correct
6 Correct 53 ms 147536 KB Output is correct
7 Correct 54 ms 147576 KB Output is correct
8 Correct 53 ms 147540 KB Output is correct
9 Correct 52 ms 147544 KB Output is correct
10 Correct 54 ms 147544 KB Output is correct
11 Correct 52 ms 147536 KB Output is correct
12 Correct 56 ms 147504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 147540 KB Output is correct
2 Correct 55 ms 147576 KB Output is correct
3 Correct 52 ms 147548 KB Output is correct
4 Correct 53 ms 147540 KB Output is correct
5 Correct 58 ms 147540 KB Output is correct
6 Correct 53 ms 147536 KB Output is correct
7 Correct 54 ms 147576 KB Output is correct
8 Correct 53 ms 147540 KB Output is correct
9 Correct 52 ms 147544 KB Output is correct
10 Correct 54 ms 147544 KB Output is correct
11 Correct 52 ms 147536 KB Output is correct
12 Correct 56 ms 147504 KB Output is correct
13 Correct 54 ms 147540 KB Output is correct
14 Correct 57 ms 147520 KB Output is correct
15 Correct 58 ms 147540 KB Output is correct
16 Correct 55 ms 147544 KB Output is correct
17 Correct 49 ms 147536 KB Output is correct
18 Correct 59 ms 147640 KB Output is correct
19 Correct 54 ms 147508 KB Output is correct
20 Correct 52 ms 147552 KB Output is correct
21 Correct 56 ms 147540 KB Output is correct
22 Correct 49 ms 147536 KB Output is correct
23 Correct 50 ms 147536 KB Output is correct
24 Correct 49 ms 147680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 581 ms 190140 KB Output is correct
2 Correct 1138 ms 227952 KB Output is correct
3 Correct 2182 ms 259124 KB Output is correct
4 Correct 3833 ms 299676 KB Output is correct
5 Correct 703 ms 212060 KB Output is correct
6 Correct 1569 ms 301648 KB Output is correct
7 Correct 3094 ms 394064 KB Output is correct
8 Execution timed out 5040 ms 509120 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 147540 KB Output is correct
2 Correct 55 ms 147576 KB Output is correct
3 Correct 52 ms 147548 KB Output is correct
4 Correct 53 ms 147540 KB Output is correct
5 Correct 58 ms 147540 KB Output is correct
6 Correct 53 ms 147536 KB Output is correct
7 Correct 54 ms 147576 KB Output is correct
8 Correct 53 ms 147540 KB Output is correct
9 Correct 52 ms 147544 KB Output is correct
10 Correct 54 ms 147544 KB Output is correct
11 Correct 52 ms 147536 KB Output is correct
12 Correct 56 ms 147504 KB Output is correct
13 Correct 54 ms 147540 KB Output is correct
14 Correct 57 ms 147520 KB Output is correct
15 Correct 58 ms 147540 KB Output is correct
16 Correct 55 ms 147544 KB Output is correct
17 Correct 49 ms 147536 KB Output is correct
18 Correct 59 ms 147640 KB Output is correct
19 Correct 54 ms 147508 KB Output is correct
20 Correct 52 ms 147552 KB Output is correct
21 Correct 56 ms 147540 KB Output is correct
22 Correct 49 ms 147536 KB Output is correct
23 Correct 50 ms 147536 KB Output is correct
24 Correct 49 ms 147680 KB Output is correct
25 Correct 581 ms 190140 KB Output is correct
26 Correct 1138 ms 227952 KB Output is correct
27 Correct 2182 ms 259124 KB Output is correct
28 Correct 3833 ms 299676 KB Output is correct
29 Correct 703 ms 212060 KB Output is correct
30 Correct 1569 ms 301648 KB Output is correct
31 Correct 3094 ms 394064 KB Output is correct
32 Execution timed out 5040 ms 509120 KB Time limit exceeded
33 Halted 0 ms 0 KB -