# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
404494 | 2021-05-14T13:55:44 Z | radaiosm7 | Fountain (eJOI20_fountain) | C++ | 245 ms | 17604 KB |
#include <bits/stdc++.h> using namespace std; int n, q, r, i, j; long long d[100005], c[100005], v, pref[100005]; stack<pair<long long, int> > diams; int up[100005][20]; int p[100005]; int main() { scanf("%d%d", &n, &q); for (i=1; i <= n; ++i) { scanf("%lld%lld", &d[i], &c[i]); } diams.push(make_pair(LONG_LONG_MAX, 0)); pref[0] = 0LL; for (i=0; i < 20; ++i) { up[0][i] = 0; } for (i=n; i >= 1; --i) { while (diams.top().first <= d[i]) diams.pop(); p[i] = diams.top().second; diams.push(make_pair(d[i], i)); pref[i] = pref[p[i]]+c[i]; up[i][0] = p[i]; for (j=1; j < 20; ++j) { up[i][j] = up[up[i][j-1]][j-1]; } } while (q--) { scanf("%d%lld", &r, &v); if (v > pref[r]) { printf("0\n"); } else { for (i=19; i >= 0; --i) { if (v > pref[r]-pref[up[r][i]]) { v -= pref[r]-pref[up[r][i]]; r = up[r][i]; } } printf("%d\n", r); } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 316 KB | Output is correct |
3 | Correct | 2 ms | 324 KB | Output is correct |
4 | Correct | 2 ms | 448 KB | Output is correct |
5 | Correct | 2 ms | 448 KB | Output is correct |
6 | Correct | 2 ms | 380 KB | Output is correct |
7 | Correct | 2 ms | 460 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 198 ms | 15536 KB | Output is correct |
2 | Correct | 180 ms | 14812 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 316 KB | Output is correct |
3 | Correct | 2 ms | 324 KB | Output is correct |
4 | Correct | 2 ms | 448 KB | Output is correct |
5 | Correct | 2 ms | 448 KB | Output is correct |
6 | Correct | 2 ms | 380 KB | Output is correct |
7 | Correct | 2 ms | 460 KB | Output is correct |
8 | Correct | 198 ms | 15536 KB | Output is correct |
9 | Correct | 180 ms | 14812 KB | Output is correct |
10 | Correct | 2 ms | 452 KB | Output is correct |
11 | Correct | 80 ms | 8524 KB | Output is correct |
12 | Correct | 245 ms | 17604 KB | Output is correct |
13 | Correct | 181 ms | 15944 KB | Output is correct |
14 | Correct | 140 ms | 14916 KB | Output is correct |
15 | Correct | 138 ms | 15336 KB | Output is correct |