# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
551841 | 2022-04-21T17:15:21 Z | jmyszka2007 | Fountain (eJOI20_fountain) | C++14 | 334 ms | 30208 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; constexpr int LIM = 1e5; int nxt[LIM + 10][20]; ll cost[LIM + 10][20]; int tab[LIM + 10]; int n; int que(int a, int ile) { for(int j = 18; j >= 1; j--) { if(cost[a][j] < ile) { ile -= cost[a][j]; a = nxt[a][j]; } } if(a == n + 1) { a = 0; } return a; } int main() { int t; scanf("%d%d", &n, &t); for(int i = 1; i <= n; i++) { scanf("%d%lld", &tab[i], &cost[i][1]); } stack<pair<int, int> >s; s.push({INT_MAX, n + 1}); for(int i = n; i >= 1; i--) { while(!s.empty() && s.top().first <= tab[i]) { s.pop(); } nxt[i][1] = s.top().second; s.push({tab[i], i}); } nxt[n + 1][1] = n + 1; cost[n + 1][1] = INT_MAX; for(int j = 2; j <= 18; j++) { for(int i = 1; i <= n + 1; i++) { nxt[i][j] = nxt[nxt[i][j - 1]][j - 1]; cost[i][j] = cost[i][j - 1] + cost[nxt[i][j - 1]][j - 1]; } } while(t--) { int a, b; scanf("%d%d", &a, &b); printf("%d\n", que(a, b)); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 2 ms | 596 KB | Output is correct |
6 | Correct | 2 ms | 596 KB | Output is correct |
7 | Correct | 1 ms | 588 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 209 ms | 24576 KB | Output is correct |
2 | Correct | 217 ms | 22712 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 468 KB | Output is correct |
4 | Correct | 1 ms | 468 KB | Output is correct |
5 | Correct | 2 ms | 596 KB | Output is correct |
6 | Correct | 2 ms | 596 KB | Output is correct |
7 | Correct | 1 ms | 588 KB | Output is correct |
8 | Correct | 209 ms | 24576 KB | Output is correct |
9 | Correct | 217 ms | 22712 KB | Output is correct |
10 | Correct | 1 ms | 596 KB | Output is correct |
11 | Correct | 90 ms | 15840 KB | Output is correct |
12 | Correct | 334 ms | 30208 KB | Output is correct |
13 | Correct | 211 ms | 29032 KB | Output is correct |
14 | Correct | 173 ms | 28416 KB | Output is correct |
15 | Correct | 135 ms | 28476 KB | Output is correct |