Submission #51524

# Submission time Handle Problem Language Result Execution time Memory
51524 2018-06-18T07:06:44 Z WA_TLE Ball Machine (BOI13_ballmachine) C++14
0 / 100
616 ms 79456 KB
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
//オイラーツアー
//addは自明
//eraseは留年二分探索
vector<int>oya;
vector<vector<int>>ko;
vector<int>tour;
vector<int>sai;
int ddfs(int ter){
	sai[ter]=ter;
	for(auto it:ko[ter]){mineq(sai[ter],ddfs(it));}
	return sai[ter];
}
void dfs(int ter){
	vector<pair<int,int>>aaa;
	for(auto it:ko[ter]){aaa.pub(mp(sai[it],it));}
	SO(aaa);
	for(auto it:aaa){dfs(it.sec);}
	tour.pub(ter);
}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int i,n,q;cin>>n>>q;
	//まずはオイラーツアーを構築する
	oya.res(n);
	ko.res(n);
	int rot=-1;
	for(i=0;i<n;i++){
		int a;cin>>a;a--;
		if(a<0){rot=i;}
		oya[i]=a;
		ko[a].pub(i);
	}
	sai.res(n);
	ddfs(rot);
	tour.reserve(n);
	dfs(rot);
	for(auto it:tour){cerr<<it<<" ";}cerr<<endl;
	vector<int>yusen(n);
	for(i=0;i<n;i++){yusen[tour[i]]=i;}
	priority_queue<int,vector<int>,greater<int>> que;
	vector<bool>aru(n+1);//aru[n]は常に空
	oya[rot]=n;
	for(i=0;i<n;i++){que.push(i);}
	array<vector<int>,17>dab;
	dab[0]=oya;
	dab[0].pub(n);
	for(int h=1;h<17;h++){
		dab[h].res(n+1);
		for(i=0;i<=n;i++){dab[h][i]=dab[h-1][dab[h-1][i]];}
	}
	while(q--){
		int type;cin>>type;
		if(type==1){
			int k;cin>>k;
			while(k--){
				//入る場所を求める
				int bas=tour[que.top()];
				que.pop();
				aru[bas]=1;
				if(k==0){cout<<bas+1<<"\n";}
			}
		}else{
			int x;cin>>x;
			//ない場所 を二分探索で求める
			int ans=0,bas=x-1;
			for(int h=16;h>=0;h--){
				if(aru[dab[h][bas]]){
					ans+=(1<<h);
					bas=dab[h][bas];
				}
			}
			aru[bas]=0;
			que.push(bas);
			cout<<ans<<"\n";
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 504 KB Output isn't correct
2 Runtime error 316 ms 10492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 254 ms 14900 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Incorrect 2 ms 14900 KB Output isn't correct
5 Incorrect 3 ms 14900 KB Output isn't correct
6 Incorrect 6 ms 14900 KB Output isn't correct
7 Incorrect 6 ms 14900 KB Output isn't correct
8 Incorrect 6 ms 14900 KB Output isn't correct
9 Incorrect 19 ms 14900 KB Output isn't correct
10 Runtime error 69 ms 14900 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 294 ms 14900 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 250 ms 17688 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 294 ms 18564 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 92 ms 18564 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 441 ms 30072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 364 ms 32756 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 166 ms 32756 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 149 ms 32756 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 154 ms 32756 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 139 ms 32756 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 91 ms 32756 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 432 ms 36332 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 476 ms 44512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 457 ms 45676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 451 ms 45676 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 418 ms 48844 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 370 ms 48844 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 219 ms 48844 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 470 ms 48844 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 405 ms 50708 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 377 ms 52396 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 343 ms 52396 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 361 ms 52396 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 368 ms 52396 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 375 ms 54436 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 535 ms 61332 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 575 ms 61332 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 489 ms 61332 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 455 ms 61332 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 616 ms 67664 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 415 ms 67664 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 529 ms 67664 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 435 ms 67664 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 464 ms 72752 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 578 ms 76636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 477 ms 76636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 604 ms 76636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 470 ms 76636 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 426 ms 79456 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 369 ms 79456 KB Execution killed with signal 11 (could be triggered by violating memory limits)