Submission #591976

# Submission time Handle Problem Language Result Execution time Memory
591976 2022-07-08T10:13:14 Z piOOE Fire (JOI20_ho_t5) C++17
8 / 100
1000 ms 4704 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

template<typename T, class F = function<T(const T&, const T&)>>
class SegTree {
public:
    T neutral = 0;
    vector <T> t;
    int sz;
    F func;

    SegTree() = default;
    SegTree(int n, const F& f, T x = 0): func(f) {
        init(n, x);
    }

    void init(int n, T x = 0) {
        sz = n;
        neutral = x;
        t.assign(sz << 1, x);
    }

    void modify(int i, T v) {
        int x = i + sz;
        t[x] = v;
        x >>= 1;
        while (x) {
            t[x] = func(t[x << 1], t[x << 1 | 1]);
            x >>= 1;
        }
    }

    T get(int l, int r) {
        l += sz;
        r += sz;
        T ans = neutral;
        while (l < r) {
            if (l & 1) {
                ans = func(ans, t[l++]);
            }
            if (r & 1) {
                ans = func(ans, t[--r]);
            }
            l >>= 1;
            r >>= 1;
        }
        return ans;
    }

};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<int> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    SegTree<int> st(n, [](int i, int j) {return max(i, j);});
    for (int i = 0; i < n; ++i) {
        st.modify(i, s[i]);
    }
    while (q--) {
        int t, l, r;
        cin >> t >> l >> r;
        ll ans = 0;
        for (int i = l - 1; i < r; ++i) {
            ans += st.get(max(0, i - t), i + 1);
        }
        cout << ans << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 1087 ms 2608 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 117 ms 4520 KB Output is correct
3 Correct 117 ms 4396 KB Output is correct
4 Correct 126 ms 4564 KB Output is correct
5 Correct 122 ms 4428 KB Output is correct
6 Correct 114 ms 4576 KB Output is correct
7 Correct 137 ms 4560 KB Output is correct
8 Correct 127 ms 4480 KB Output is correct
9 Correct 115 ms 4488 KB Output is correct
10 Correct 116 ms 4428 KB Output is correct
11 Correct 135 ms 4704 KB Output is correct
12 Correct 131 ms 4508 KB Output is correct
13 Correct 120 ms 4576 KB Output is correct
14 Correct 116 ms 4616 KB Output is correct
15 Correct 129 ms 4572 KB Output is correct
16 Correct 113 ms 4492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1088 ms 2492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Execution timed out 1087 ms 2608 KB Time limit exceeded
34 Halted 0 ms 0 KB -