Submission #468658

# Submission time Handle Problem Language Result Execution time Memory
468658 2021-08-29T08:54:42 Z mychecksedad Fountain (eJOI20_fountain) C++17
0 / 100
234 ms 18124 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10, K = 20;
#define pb push_back
int n, qq, c[N], d[N], dp[N][K+1], go[N][K+1], a, b;
int main(){
	cin.tie(0); ios::sync_with_stdio(0);
	cin >> n >> qq;
	for(int i = 1; i <= n; i++){
		cin >> d[i] >> c[i];
	}
	deque<pair<int, int>> q;
	q.pb({1e9+7, n + 1});
	go[n + 1][0] = n + 1;
	c[n + 1] = 0;
	dp[n + 1][0] = 0;
	for(int i = n; i >= 1; i--){
		while(!q.empty() && q.back().first <= d[i]) q.pop_back();
		go[i][0] = q.back().second;
		dp[i][0] = c[i];
		q.pb({d[i], i});
	}
	

	for(int k = 1; k <= K; k++){
		for(int v = 1; v <= n+1; v++){
			go[v][k] = go[go[v][k - 1]][k - 1];
			dp[v][k] = dp[v][k - 1] + dp[go[v][k-1]][k-1];
			// cout << go[v][k] << ' ' << v << ' ' << k << endl;
		}
		// cout << endl;
	}


	for(int i = 0; i < qq; i++){
		cin >> a >> b;
		int v = a;
		if(c[v] >= b){
			cout << v << '\n';
			continue;
		}
		for(int i = K; i > 0; i--){
			if(dp[v][i] <= b && b > 0) b -= dp[v][i], v = go[v][i];
			// cout << v<<endl;
		}
		if(dp[go[v][0]][0] >= b && b>0) v = go[v][0];
		cout << (v==n+1?0:v) << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 234 ms 18124 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -