답안 #1012952

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1012952 2024-07-03T01:22:28 Z vjudge1 Fountain (eJOI20_fountain) C++14
100 / 100
204 ms 42600 KB
#include <bits/stdc++.h>
#define res register int
#define int long long
using namespace std;
const int N = 200005, LOGN = 20;
int n, m, d[N], c[N], f[LOGN][N], tot, sum[LOGN][N];
int ksm (int x, int y) {
	int s = 1;
	for (; y; x = x * x, y >>= 1)
		if (y & 1) s = s * x;
	return s;
}
struct STK {
	int val, id;
} st[N];
signed main () {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	cin >> n >> m;
	for (res i = 1; i <= n; i ++) cin >> d[i] >> c[i];
	for (res i = 1; i <= n; i ++) {
		while (tot && st[tot].val < d[i])
			f[0][st[tot].id] = i, sum[0][st[tot].id] = c[i], tot --;
        st[++ tot] = {d[i], i};
	}
	for (res j = 1; j < LOGN; j ++)
		for (res i = 1; i <= n; i ++) {
			f[j][i] = f[j - 1][f[j - 1][i]];
			sum[j][i] = sum[j - 1][i] + sum[j - 1][f[j - 1][i]];
		}
	for (res i = 1, x, v; i <= m; i ++) {
		cin >> x >> v;
		v -= c[x];
		for (res j = LOGN - 1; ~j; j --)
			if (sum[j][x] && v > sum[j][x]) v -= sum[j][x], x = f[j][x];
		if (v > 0) x = f[0][x];
		cout << x << '\n';
	}
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 7004 KB Output is correct
3 Correct 2 ms 8944 KB Output is correct
4 Correct 1 ms 7004 KB Output is correct
5 Correct 1 ms 7004 KB Output is correct
6 Correct 2 ms 7004 KB Output is correct
7 Correct 2 ms 7000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 38740 KB Output is correct
2 Correct 117 ms 38224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8796 KB Output is correct
2 Correct 1 ms 7004 KB Output is correct
3 Correct 2 ms 8944 KB Output is correct
4 Correct 1 ms 7004 KB Output is correct
5 Correct 1 ms 7004 KB Output is correct
6 Correct 2 ms 7004 KB Output is correct
7 Correct 2 ms 7000 KB Output is correct
8 Correct 121 ms 38740 KB Output is correct
9 Correct 117 ms 38224 KB Output is correct
10 Correct 2 ms 9048 KB Output is correct
11 Correct 53 ms 27216 KB Output is correct
12 Correct 204 ms 42076 KB Output is correct
13 Correct 131 ms 42600 KB Output is correct
14 Correct 86 ms 40788 KB Output is correct
15 Correct 77 ms 41984 KB Output is correct