Submission #466699

# Submission time Handle Problem Language Result Execution time Memory
466699 2021-08-20T09:58:43 Z Clan328 Fountain (eJOI20_fountain) C++17
0 / 100
358 ms 34684 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define nL '\n'
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

vvl up;
vvl sum;

// void readInput(ll n, ll i) {
// 	ll d;
// 	ll c;
// 	cin >> d >> c;

// 	if (i < n)
// 		readInput(n, i+1);

	

// 	if (j > n)
// 		j = 0;

// 	up[i][0] = j;
// 	sum[i][0] = c;
// }

int main() {
	#ifdef LOCAL
		freopen("io/input.txt", "r", stdin);
		freopen("io/output.txt", "w", stdout);
	#endif

	ios::sync_with_stdio(0);
	cin.tie(0);

	ll n, q;
	cin >> n >> q;
	vpll input(n+1);
	for (int i = 1; i <= n; i++)
		cin >> input[i].first >> input[i].second;

	ll LOG = log2(n);

	up = vvl(n+1, vl(LOG));
	sum = vvl(n+1, vl(LOG));
	
	stack<ll> stk;
	for (int i = n; i > 0; i--) {
		while (!stk.empty() && input[stk.top()].first <= input[i].first)
			stk.pop();
		if (!stk.empty())
			up[i][0] = stk.top();
		else
			up[i][0] = 0;
		sum[i][0] = input[i].second;
		stk.push(i);
	}

	for (ll v = n; v > 0; v--) {
		for (ll j = 1; j < LOG; j++) {
			up[v][j] = up[up[v][j-1]][j-1];
			sum[v][j] = sum[v][j-1] + sum[up[v][j-1]][j-1];
		}
	}

	while (q--) {
		ll r;
		ll v;
		cin >> r >> v;

		for (ll i = LOG-1; i >= 0; i--) {
			if (sum[r][i] < v) {
				v -= sum[r][i];
				r = up[r][i];
			}
		}

		cout << r << nL;
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Incorrect 2 ms 460 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 358 ms 34684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Incorrect 2 ms 460 KB Output isn't correct
6 Halted 0 ms 0 KB -