# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
551833 | jmyszka2007 | Fountain (eJOI20_fountain) | C++17 | 219 ms | 27468 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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));
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |