Submission #588381

# Submission time Handle Problem Language Result Execution time Memory
588381 2022-07-03T08:44:44 Z dozer Fountain (eJOI20_fountain) C++14
0 / 100
238 ms 32540 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sp " "
#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define N 500005
#define pii pair<int, int>
#define st first
#define nd second
#define modulo 1000000007
#define LOGN 18
#define int long long

int nxt[LOGN][N], arr[N], c[N], sum[LOGN][N]; 

int32_t main()
{
	fastio();

	int n, q;
	cin>>n>>q;
	for (int i = 1; i <= n; i++)
		cin>>arr[i]>>c[i];
	arr[0] = modulo;
	nxt[0][n] = 0;
	for (int i = n - 1; i >= 1; i--)
	{
		nxt[0][i] = i + 1;
		while(arr[nxt[0][i]] <= arr[i]) nxt[0][i] = nxt[0][nxt[0][i]];
		sum[0][i] = c[nxt[0][i]];
		//cout<<i<<sp<<nxt[0][i]<<endl;
	}
	for (int i = 1; i < LOGN; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			sum[i][j] = sum[i - 1][j] + sum[i - 1][nxt[i - 1][j]];
			nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
			//cout<<i<<sp<<j<<sp<<sum[i][j]<<endl;
		}
	}

	while(q--)
	{
		int r, v;
		cin>>r>>v;
		if (v <= c[r])
		{
			cout<<r<<endl;
			continue;
		}
		v -= c[r];
		int curr = r;
		
		for (int i = LOGN - 1; i >= 0; i--)
		{
			int tmp = nxt[i][curr];
			if (sum[i][curr] <= v)
			{
				v -= sum[i][curr];
				curr = tmp;
			}
		}
		
		cout<<nxt[0][curr]<<endl;
	}
	

	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 238 ms 32540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -