| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 467187 | Mamedov | Fountain (eJOI20_fountain) | C++17 | 331 ms | 20432 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ll long long
#define ui unsigned int
#define pii pair<int, int>
#define pis pair<int, string>
#define piii pair<int, pii>
#define pb push_back
#define f first
#define s second
#define oo 2000000002
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int up = 1e5 + 5;
const int lg = 18;
int D[up], C[up];
int sum[up][lg], par[up][lg];
void buildST(int n) {
    stack<int>st;
    D[0] = oo;
    st.push(0);
    for(int i = n; i >= 1; --i) {
        while(D[st.top()] <= D[i]) {
            st.pop();
        }
        par[i][0] = st.top();
        st.push(i);
    }
    for(int i = 0; i <= n; ++i) {
        sum[i][0] = C[i];
    }
    for(int j = 1; j < lg; ++j) {
        for(int i = 1; i <= n; ++i) {
            par[i][j] = par[par[i][j - 1]][j - 1];
            sum[i][j] = sum[i][j - 1] + sum[par[i][j - 1]][j - 1];
        }
    }
}
int query(int id, int vol) {
    for(int i = lg - 1; i >= 0 && id; --i) {
        if(sum[id][i] < vol) {
            vol -= sum[id][i];
            id = par[id][i];
        }
    }
    return id;
}
void solve() {
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i) {
        scanf("%d%d", D + i, C + i);
    }
    buildST(n);
    int id, vol;
    while(q--) {
        scanf("%d%d", &id, &vol);
        printf("%d\n", query(id, vol));
    }
}
int main() {
    solve();
}
컴파일 시 표준 에러 (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... | ||||
