Submission #501602

# Submission time Handle Problem Language Result Execution time Memory
501602 2022-01-04T07:08:14 Z dxz05 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 203044 KB
#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()

#define MP make_pair

inline void merge(vector<int> &v, const vector<int> &a, const vector<int> &b){
    int n = a.size(), m = b.size();
    int i = 0, j = 0;
    while (i < n || j < m){
        if (i < n && (j == m || a[i] < b[j])) v.push_back(a[i++]); else
            v.push_back(b[j++]);
    }
}

#define tree qrisdfni

struct node{
    int ans = 0;
    int mx = -1;
    vector<int> vec;
    node(){};
} tree[2200000];

int size = 1;

inline int lwb(int x, const vector<int> &v){
    int i = lower_bound(all(v), x) - v.begin() - 1;
    if (i >= 0) return v[i];
    return -1;
}

inline void build(int v, int tl, int tr, const vector<int> &a){
    tree[v].vec.reserve(tr - tl + 1);

    if (tl == tr){
        tree[v].ans = 0;
        tree[v].mx = a[tl - 1];
        tree[v].vec = {a[tl - 1]};
        return;
    }

    int tm = (tl + tr) >> 1;
    build(v + v, tl, tm, a);
    build(v + v + 1, tm + 1, tr, a);

    merge(tree[v].vec, tree[v + v].vec, tree[v + v + 1].vec);
    tree[v].mx = max(tree[v + v].mx, tree[v + v + 1].mx);
    tree[v].ans = max(tree[v + v].ans, tree[v + v + 1].ans);

    int x = lwb(tree[v + v].mx, tree[v + v + 1].vec);
    if (x != -1) tree[v].ans = max(tree[v].ans, tree[v + v].mx + x);
}

inline void init(const vector<int> &a){
    size = a.size();
    build(1, 1, size, a);
}

inline int biggest(int v, int tl, int tr, int l, int r, int key){
    if (l <= tl && tr <= r){
        int x = lwb(key, tree[v].vec);
        return (x != -1 ? x : -1);
    }
    if (tl > r || tr < l) return -1;
    int tm = (tl + tr) >> 1;
    return max(biggest(v + v, tl, tm, l, r, key), biggest(v + v + 1, tm + 1, tr, l, r, key));
}

inline pair<int, int> get(int v, int tl, int tr, int l, int r){
    if (l <= tl && tr <= r) return MP(tree[v].ans, tree[v].mx);
    if (tl > r || tr < l) return MP(0, -1);
    int tm = (tl + tr) >> 1;
    auto lf = get(v + v, tl, tm, l, r), rg = get(v + v + 1, tm + 1, tr, l, r);
    int ans = max(lf.first, rg.first);
    if (lf.second != -1 && rg.second != -1) {
        int x = biggest(1, 1, size, tm + 1, min(r, tr), lf.second);
        if (x != -1) ans = max(ans, lf.second + x);
    }

    return MP(ans, max(lf.second, rg.second));
}

inline int get(int l, int r){
    return get(1, 1, size, l, r).first;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int n, q;
    cin >> n >> q;

    vector<int> a(n);
    for (int &i : a) cin >> i;

    init(a);

    while (q--) {
        int l, r, k;
        cin >> l >> r >> k;
        cout << (get(l, r) <= k) << endl;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 33 ms 69136 KB Output is correct
2 Correct 33 ms 69076 KB Output is correct
3 Correct 36 ms 69108 KB Output is correct
4 Correct 39 ms 69104 KB Output is correct
5 Correct 37 ms 69076 KB Output is correct
6 Correct 35 ms 69120 KB Output is correct
7 Correct 35 ms 69124 KB Output is correct
8 Correct 42 ms 69208 KB Output is correct
9 Correct 35 ms 69224 KB Output is correct
10 Correct 34 ms 69128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 69136 KB Output is correct
2 Correct 33 ms 69076 KB Output is correct
3 Correct 36 ms 69108 KB Output is correct
4 Correct 39 ms 69104 KB Output is correct
5 Correct 37 ms 69076 KB Output is correct
6 Correct 35 ms 69120 KB Output is correct
7 Correct 35 ms 69124 KB Output is correct
8 Correct 42 ms 69208 KB Output is correct
9 Correct 35 ms 69224 KB Output is correct
10 Correct 34 ms 69128 KB Output is correct
11 Correct 46 ms 69336 KB Output is correct
12 Correct 46 ms 69804 KB Output is correct
13 Correct 49 ms 69588 KB Output is correct
14 Correct 51 ms 69616 KB Output is correct
15 Correct 51 ms 69716 KB Output is correct
16 Correct 49 ms 69600 KB Output is correct
17 Correct 44 ms 69588 KB Output is correct
18 Correct 50 ms 69664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3063 ms 203044 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 541 ms 81228 KB Output is correct
2 Correct 591 ms 81556 KB Output is correct
3 Correct 530 ms 81236 KB Output is correct
4 Correct 530 ms 81192 KB Output is correct
5 Correct 512 ms 81284 KB Output is correct
6 Correct 540 ms 81220 KB Output is correct
7 Correct 539 ms 81292 KB Output is correct
8 Correct 455 ms 81360 KB Output is correct
9 Correct 206 ms 69404 KB Output is correct
10 Correct 438 ms 81180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 69136 KB Output is correct
2 Correct 33 ms 69076 KB Output is correct
3 Correct 36 ms 69108 KB Output is correct
4 Correct 39 ms 69104 KB Output is correct
5 Correct 37 ms 69076 KB Output is correct
6 Correct 35 ms 69120 KB Output is correct
7 Correct 35 ms 69124 KB Output is correct
8 Correct 42 ms 69208 KB Output is correct
9 Correct 35 ms 69224 KB Output is correct
10 Correct 34 ms 69128 KB Output is correct
11 Correct 46 ms 69336 KB Output is correct
12 Correct 46 ms 69804 KB Output is correct
13 Correct 49 ms 69588 KB Output is correct
14 Correct 51 ms 69616 KB Output is correct
15 Correct 51 ms 69716 KB Output is correct
16 Correct 49 ms 69600 KB Output is correct
17 Correct 44 ms 69588 KB Output is correct
18 Correct 50 ms 69664 KB Output is correct
19 Correct 1193 ms 94220 KB Output is correct
20 Correct 1179 ms 94092 KB Output is correct
21 Correct 1254 ms 94196 KB Output is correct
22 Correct 1235 ms 94200 KB Output is correct
23 Correct 1215 ms 94260 KB Output is correct
24 Correct 1134 ms 94040 KB Output is correct
25 Correct 1122 ms 94196 KB Output is correct
26 Correct 1163 ms 94100 KB Output is correct
27 Correct 1217 ms 94208 KB Output is correct
28 Correct 1207 ms 94108 KB Output is correct
29 Correct 1093 ms 94104 KB Output is correct
30 Correct 1125 ms 94232 KB Output is correct
31 Correct 1129 ms 94140 KB Output is correct
32 Correct 1180 ms 94336 KB Output is correct
33 Correct 1126 ms 94044 KB Output is correct
34 Correct 1149 ms 94116 KB Output is correct
35 Correct 1142 ms 94268 KB Output is correct
36 Correct 1123 ms 94152 KB Output is correct
37 Correct 1178 ms 94124 KB Output is correct
38 Correct 1144 ms 94024 KB Output is correct
39 Correct 1022 ms 94212 KB Output is correct
40 Correct 760 ms 85708 KB Output is correct
41 Correct 954 ms 94184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 69136 KB Output is correct
2 Correct 33 ms 69076 KB Output is correct
3 Correct 36 ms 69108 KB Output is correct
4 Correct 39 ms 69104 KB Output is correct
5 Correct 37 ms 69076 KB Output is correct
6 Correct 35 ms 69120 KB Output is correct
7 Correct 35 ms 69124 KB Output is correct
8 Correct 42 ms 69208 KB Output is correct
9 Correct 35 ms 69224 KB Output is correct
10 Correct 34 ms 69128 KB Output is correct
11 Correct 46 ms 69336 KB Output is correct
12 Correct 46 ms 69804 KB Output is correct
13 Correct 49 ms 69588 KB Output is correct
14 Correct 51 ms 69616 KB Output is correct
15 Correct 51 ms 69716 KB Output is correct
16 Correct 49 ms 69600 KB Output is correct
17 Correct 44 ms 69588 KB Output is correct
18 Correct 50 ms 69664 KB Output is correct
19 Execution timed out 3063 ms 203044 KB Time limit exceeded
20 Halted 0 ms 0 KB -