Submission #963418

# Submission time Handle Problem Language Result Execution time Memory
963418 2024-04-15T01:33:40 Z pcc Ball Machine (BOI13_ballmachine) C++17
16.1111 / 100
151 ms 45448 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>

const int mxn = 1e5+10;
vector<int> tree[mxn];
vector<int> eul;
int par[mxn][20],dep[mxn];
int N,Q;
int rt;
int dp[mxn];
int dfn[mxn];
set<int> st;

void dfs(int now){
	for(int i = 1;i<20;i++)par[now][i] = par[par[now][i-1]][i-1];
	sort(tree[now].begin(),tree[now].end());
	for(auto nxt:tree[now]){
		dep[nxt] = dep[now]+1;
		par[nxt][0] = now;
		dfs(nxt);
	}
	dfn[now] = eul.size();
	eul.push_back(now);
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>Q;
	for(int i = 1;i<=N;i++){
		int p;
		cin>>p;
		par[i][0] = p;
		tree[p].push_back(i);
		if(!p)rt = i;
	}
	par[rt][0] = rt;
	dfs(rt);
	for(int i = 0;i<N;i++)st.insert(i);
	int C = 0;
	while(Q--){
		int t,k;
		cin>>t>>k;
		int lst = 0;
		//assert(C == N-st.size());
		if(t == 1){
			C += k;
			while(k--){
				lst = eul[*st.begin()];
				st.erase(*st.begin());
				dp[lst] = 1;
			}
			cout<<lst<<'\n';
		}
		else{
			C--;
			lst = k;
			assert(dp[k]);
			for(int i = 19;i>=0;i--){
				if(dp[par[lst][i]])lst = par[lst][i];
			}
			st.insert(dfn[lst]);
			dp[lst] = 0;
			cout<<dep[k]-dep[lst]<<'\n';
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 10844 KB Execution killed with signal 6
2 Runtime error 36 ms 28116 KB Execution killed with signal 6
3 Runtime error 42 ms 28224 KB Execution killed with signal 6
4 Runtime error 6 ms 10588 KB Execution killed with signal 6
5 Runtime error 8 ms 10840 KB Execution killed with signal 6
6 Runtime error 6 ms 10844 KB Execution killed with signal 6
7 Runtime error 7 ms 10844 KB Execution killed with signal 6
8 Runtime error 9 ms 10832 KB Execution killed with signal 6
9 Runtime error 7 ms 11356 KB Execution killed with signal 6
10 Runtime error 15 ms 17240 KB Execution killed with signal 6
11 Runtime error 42 ms 28180 KB Execution killed with signal 6
12 Runtime error 35 ms 28268 KB Execution killed with signal 6
13 Runtime error 36 ms 28112 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Correct 28 ms 10332 KB Output is correct
2 Runtime error 85 ms 44116 KB Execution killed with signal 6
3 Runtime error 55 ms 36528 KB Execution killed with signal 6
4 Runtime error 22 ms 21588 KB Execution killed with signal 6
5 Runtime error 22 ms 21332 KB Execution killed with signal 6
6 Runtime error 21 ms 21340 KB Execution killed with signal 6
7 Runtime error 19 ms 19800 KB Execution killed with signal 6
8 Correct 28 ms 10520 KB Output is correct
9 Runtime error 64 ms 45008 KB Execution killed with signal 6
10 Runtime error 67 ms 44244 KB Execution killed with signal 6
11 Runtime error 70 ms 44032 KB Execution killed with signal 6
12 Runtime error 84 ms 40540 KB Execution killed with signal 6
13 Correct 77 ms 24840 KB Output is correct
14 Runtime error 60 ms 36476 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 15200 KB Output isn't correct
2 Runtime error 71 ms 40844 KB Execution killed with signal 6
3 Correct 84 ms 23644 KB Output is correct
4 Runtime error 54 ms 40652 KB Execution killed with signal 6
5 Runtime error 63 ms 40064 KB Execution killed with signal 6
6 Runtime error 55 ms 40140 KB Execution killed with signal 6
7 Runtime error 54 ms 37452 KB Execution killed with signal 6
8 Correct 101 ms 23644 KB Output is correct
9 Runtime error 125 ms 45448 KB Execution killed with signal 6
10 Runtime error 122 ms 44440 KB Execution killed with signal 6
11 Runtime error 98 ms 44364 KB Execution killed with signal 6
12 Runtime error 72 ms 41064 KB Execution killed with signal 6
13 Correct 151 ms 27036 KB Output is correct
14 Runtime error 60 ms 36552 KB Execution killed with signal 6
# Verdict Execution time Memory Grader output
1 Runtime error 71 ms 44960 KB Execution killed with signal 6
2 Runtime error 77 ms 40824 KB Execution killed with signal 6
3 Correct 110 ms 26676 KB Output is correct
4 Runtime error 66 ms 45012 KB Execution killed with signal 6
5 Runtime error 69 ms 44244 KB Execution killed with signal 6
6 Runtime error 68 ms 44240 KB Execution killed with signal 6
7 Runtime error 70 ms 40908 KB Execution killed with signal 6
8 Correct 96 ms 26664 KB Output is correct
9 Runtime error 50 ms 36492 KB Execution killed with signal 6