Submission #658144

# Submission time Handle Problem Language Result Execution time Memory
658144 2022-11-12T09:41:41 Z Danilo21 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1052 ms 107228 KB
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))

using namespace std;

class segtree{

    int n;
    vector<ll> tree;

    ll update(int s, int l, int r, int pos, ll x){
        if (l > pos || r < pos) return tree[s];
        if (l == r) return tree[s] = x;
        int m = (l + r)>>1;
        ll a = update(2*s, l, m, pos, x);
        ll b = update(2*s+1, m+1, r, pos, x);
        return tree[s] = max(a, b);
    }

    ll query(int s, int l, int r, int ql, int qr) const {
        if (l > qr || r < ql) return 0;
        if (l >= ql && r <= qr) return tree[s];
        int m = (l + r)>>1;
        ll a = query(2*s, l, m, ql, qr);
        ll b = query(2*s+1, m+1, r, ql, qr);
        return max(a, b);
    }

public:
    segtree(int n = 0){ Assign(n); }
    void Assign(int s){
        n = highpow(s);
        if (bitcnt(s) > 1) n <<= 1;
        tree.assign(2*n, 0);
    }
    void update(int pos, ll x){ update(1, 0, n-1, pos, x); }
    ll query(int l, int r) const { return query(1, 0, n-1, l, r); }
};

const ll LINF = 4e18;
const int mxN = 1e6+10, INF = 2e9;
ll n, m, a[mxN], f[mxN], ans[mxN];
array<ll, 4> q[mxN];
segtree st;

void Solve(){

    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    stack<ll> stk;
    for (int i = 0; i < n; i++){
        while (stk.size() && a[stk.top()] <= a[i]) stk.pop();
        f[i] = (stk.size() ? stk.top() : -1);
        stk.push(i);
    }
    for (int i = 0; i < m; i++){
        cin >> q[i][1] >> q[i][0] >> q[i][2];
        q[i][0]--; q[i][1]--;
        q[i][3] = i;
    }
    sort(q, q+m);
    st.Assign(n);
    for (int i = 0, j = 0; j < m; j++){
        auto [r, l, k, t] = q[j];
        for (; i < n && i <= r; i++)
            if (~f[i])
                st.update(f[i], a[i] + a[f[i]]);
        if (st.query(l, r) <= k) ans[t] = 1;
    }
    for (int i = 0; i < m; i++)
        cout << ans[i] << en;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;
    cerr << "Started!" << endl;

    int t = 1;
    //cin >> t;
    while (t--)
        Solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 5 ms 980 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 944 ms 65640 KB Output is correct
2 Correct 976 ms 74696 KB Output is correct
3 Correct 954 ms 74496 KB Output is correct
4 Correct 979 ms 74652 KB Output is correct
5 Correct 900 ms 84940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 8032 KB Output is correct
2 Correct 75 ms 9964 KB Output is correct
3 Correct 73 ms 10008 KB Output is correct
4 Correct 66 ms 9960 KB Output is correct
5 Correct 67 ms 10072 KB Output is correct
6 Correct 62 ms 9052 KB Output is correct
7 Correct 62 ms 9032 KB Output is correct
8 Correct 69 ms 9936 KB Output is correct
9 Correct 40 ms 5696 KB Output is correct
10 Correct 66 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 5 ms 980 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
19 Correct 182 ms 22328 KB Output is correct
20 Correct 188 ms 22340 KB Output is correct
21 Correct 170 ms 22216 KB Output is correct
22 Correct 176 ms 22216 KB Output is correct
23 Correct 173 ms 22352 KB Output is correct
24 Correct 145 ms 22120 KB Output is correct
25 Correct 155 ms 22016 KB Output is correct
26 Correct 154 ms 22220 KB Output is correct
27 Correct 151 ms 22284 KB Output is correct
28 Correct 162 ms 22440 KB Output is correct
29 Correct 171 ms 22412 KB Output is correct
30 Correct 156 ms 22400 KB Output is correct
31 Correct 162 ms 22488 KB Output is correct
32 Correct 166 ms 22316 KB Output is correct
33 Correct 155 ms 22328 KB Output is correct
34 Correct 146 ms 22016 KB Output is correct
35 Correct 145 ms 22000 KB Output is correct
36 Correct 143 ms 21836 KB Output is correct
37 Correct 151 ms 21784 KB Output is correct
38 Correct 142 ms 21908 KB Output is correct
39 Correct 144 ms 20940 KB Output is correct
40 Correct 119 ms 17096 KB Output is correct
41 Correct 143 ms 20652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 724 KB Output is correct
13 Correct 3 ms 724 KB Output is correct
14 Correct 5 ms 980 KB Output is correct
15 Correct 5 ms 844 KB Output is correct
16 Correct 3 ms 852 KB Output is correct
17 Correct 3 ms 724 KB Output is correct
18 Correct 3 ms 852 KB Output is correct
19 Correct 944 ms 65640 KB Output is correct
20 Correct 976 ms 74696 KB Output is correct
21 Correct 954 ms 74496 KB Output is correct
22 Correct 979 ms 74652 KB Output is correct
23 Correct 900 ms 84940 KB Output is correct
24 Correct 76 ms 8032 KB Output is correct
25 Correct 75 ms 9964 KB Output is correct
26 Correct 73 ms 10008 KB Output is correct
27 Correct 66 ms 9960 KB Output is correct
28 Correct 67 ms 10072 KB Output is correct
29 Correct 62 ms 9052 KB Output is correct
30 Correct 62 ms 9032 KB Output is correct
31 Correct 69 ms 9936 KB Output is correct
32 Correct 40 ms 5696 KB Output is correct
33 Correct 66 ms 9676 KB Output is correct
34 Correct 182 ms 22328 KB Output is correct
35 Correct 188 ms 22340 KB Output is correct
36 Correct 170 ms 22216 KB Output is correct
37 Correct 176 ms 22216 KB Output is correct
38 Correct 173 ms 22352 KB Output is correct
39 Correct 145 ms 22120 KB Output is correct
40 Correct 155 ms 22016 KB Output is correct
41 Correct 154 ms 22220 KB Output is correct
42 Correct 151 ms 22284 KB Output is correct
43 Correct 162 ms 22440 KB Output is correct
44 Correct 171 ms 22412 KB Output is correct
45 Correct 156 ms 22400 KB Output is correct
46 Correct 162 ms 22488 KB Output is correct
47 Correct 166 ms 22316 KB Output is correct
48 Correct 155 ms 22328 KB Output is correct
49 Correct 146 ms 22016 KB Output is correct
50 Correct 145 ms 22000 KB Output is correct
51 Correct 143 ms 21836 KB Output is correct
52 Correct 151 ms 21784 KB Output is correct
53 Correct 142 ms 21908 KB Output is correct
54 Correct 144 ms 20940 KB Output is correct
55 Correct 119 ms 17096 KB Output is correct
56 Correct 143 ms 20652 KB Output is correct
57 Correct 1022 ms 107228 KB Output is correct
58 Correct 1014 ms 107176 KB Output is correct
59 Correct 1014 ms 106972 KB Output is correct
60 Correct 970 ms 106904 KB Output is correct
61 Correct 1052 ms 106876 KB Output is correct
62 Correct 1040 ms 105620 KB Output is correct
63 Correct 938 ms 103728 KB Output is correct
64 Correct 827 ms 103684 KB Output is correct
65 Correct 931 ms 105340 KB Output is correct
66 Correct 916 ms 105992 KB Output is correct
67 Correct 912 ms 105308 KB Output is correct
68 Correct 959 ms 105456 KB Output is correct
69 Correct 954 ms 105652 KB Output is correct
70 Correct 936 ms 105676 KB Output is correct
71 Correct 943 ms 105408 KB Output is correct
72 Correct 941 ms 105360 KB Output is correct
73 Correct 775 ms 102280 KB Output is correct
74 Correct 804 ms 103284 KB Output is correct
75 Correct 767 ms 103504 KB Output is correct
76 Correct 771 ms 102376 KB Output is correct
77 Correct 762 ms 103336 KB Output is correct
78 Correct 836 ms 100840 KB Output is correct
79 Correct 635 ms 80380 KB Output is correct
80 Correct 827 ms 98248 KB Output is correct