답안 #494923

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494923 2021-12-17T13:58:04 Z uncripted Fountain (eJOI20_fountain) C++11
30 / 100
529 ms 35352 KB
//unfin
#include<bits/stdc++.h>
#define s second
#define f first
using namespace std;
pair<long long,long long> go[100005][20];
long long par[100005];
long long d[100005];
long long c[100005];
int main(){
long long n,q;
cin>>n>>q;

for(long long i=1; i<=n; i++){
cin>>d[i];
cin>>c[i];

}
d[n+1]=INT_MAX;
d[0]=INT_MAX;
stack<long long> s;
s.push(n+1);
for(long long i=n; i>=1; i--){
	while(d[i]>=d[s.top()]){
		s.pop();
	}
	go[i][0].s=s.top();
	par[s.top()]=i;
	go[i][0].f=c[i];
	s.push(i);
}
/*
for(long long i=1; i<20; i++){
	for(long long ii=1; ii<200005; ii++){
	
			go[ii][i].s=long long_MAX;

		
	}
}*/
for(long long i=1; i<20; i++){
	for(long long ii=1; ii<100005; ii++){
		go[ii][i].f=go[go[ii][i-1].s][i-1].f+go[ii][i-1].f;
		go[ii][i].s=go[go[ii][i-1].s][i-1].s;
		if(ii>n){
			go[ii][i].s=n+1;
		}
	}
}
for(long long i=1; i<=q; i++){
	long long x,y;
	cin>>x>>y;
	long long j=19;
	long long st=x;
	while(true){
	if(y>=go[st][19].f){
		cout<<"0"<<endl;
		break;
	}
	if(j==0 && y<=go[st][j].f){
		cout<<st<<endl;
		break;
	}
	while(y<go[st][j].f && j>0){
		j--;
	}
	y-=go[st][j].f;
//	cout<<y<<" y"<<endl;
//cout<<j<<" "<<go[st][j].s<<" "<<go[st][j].f<<endl;
//cout<<st<<" "<<j<<endl;
	
	//	cout<<go[go[st][i-1].s][j-1].s<<"bruh "<<endl;
	if(y<=0){
		cout<<par[go[st][j].s]<<endl;
		break;
	}
	//if()

		st=go[st][j].s;
		
	}
	
	
	
}	
	
	
	
	
	
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 31496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 35352 KB Output is correct
2 Correct 529 ms 35188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 31496 KB Output isn't correct
2 Halted 0 ms 0 KB -