Submission #467186

# Submission time Handle Problem Language Result Execution time Memory
467186 2021-08-21T23:21:02 Z Mamedov Fountain (eJOI20_fountain) C++17
0 / 100
178 ms 15216 KB
#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 + 1, C + i + 1);
    }
    buildST(n);
    int id, vol;
    while(q--) {
        scanf("%d%d", &id, &vol);
        printf("%d\n", query(id, vol));
    }
}
int main() {
    solve();
}

Compilation message

fountain.cpp: In function 'void solve()':
fountain.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
fountain.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         scanf("%d%d", D + i + 1, C + i + 1);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:61:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         scanf("%d%d", &id, &vol);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 178 ms 15216 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -