Submission #964946

#TimeUsernameProblemLanguageResultExecution timeMemory
964946zxciganFountain (eJOI20_fountain)C++17
30 / 100
1512 ms3252 KiB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6 + 1;
const int mod = 1e9 + 7;

template <typename T>
bool umx(T& a, T b) {
    return (a < b ? a = b, 1 : 0);
}
template <typename T>
bool umn(T& a, T b) {
    return (a > b ? a = b, 1 : 0);
}

void solve () {
    int n, q;
    cin >> n >> q;
    vector<int> d (n + 1), c (n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> d[i] >> c[i];
    }
    vector<int> bigr(n + 1);
    vector<int> ve;
    for (int i = 1; i <= n; ++i) {
        while ((int)ve.size() && d[ve.back()] < d[i]) {
            bigr[ve.back()] = i;
            ve.pop_back();
        }
        ve.push_back(i);
    }
    while (q--) {
        int r, v;
        cin >> r >> v;
        while (r) {
            v -= c[r];
            if (v <= 0) break;
            r = bigr[r];
        }
        cout << r << "\n";
    }
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //    freopen ("input.txt", "r", stdin);
//    freopen ("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while (T--) solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...