답안 #964946

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964946 2024-04-17T18:24:19 Z zxcigan Fountain (eJOI20_fountain) C++17
30 / 100
1500 ms 3252 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1512 ms 3252 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Correct 1 ms 356 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Execution timed out 1512 ms 3252 KB Time limit exceeded
9 Halted 0 ms 0 KB -