Submission #896925

# Submission time Handle Problem Language Result Execution time Memory
896925 2024-01-02T11:09:13 Z otarius Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1062 ms 98676 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <stack>
#include <iomanip>
using namespace std;

void __print(int x) { cerr << x; }

void __print(long x) { cerr << x; }

void __print(long long x) { cerr << x; }

void __print(unsigned x) { cerr << x; }

void __print(unsigned long x) { cerr << x; }

void __print(unsigned long long x) { cerr << x; }

void __print(float x) { cerr << x; }

void __print(double x) { cerr << x; }

void __print(long double x) { cerr << x; }

void __print(char x) { cerr << '\'' << x << '\''; }

void __print(const char *x) { cerr << '\"' << x << '\"'; }

void __print(const string &x) { cerr << '\"' << x << '\"'; }

void __print(bool x) { cerr << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}

template<typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i: x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}

void _print() { cerr << "]\n"; }

template<typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long

// #define int long long
// #define int unsigned long long

const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;

int t[4000005];
int arr[1000005], l, r, k;
vector<pair<int, pii>> q[1000005];
void update(int v, int tl, int tr, int pos, int val) {
    if (tl == tr) {
        t[v] = val;
        return;
    } int tm = (tl + tr) / 2;
    if (pos <= tm) update(2 * v, tl, tm, pos, val);
    else update(2 * v + 1, tm + 1, tr, pos, val);
    t[v] = max(t[2 * v], t[2 * v + 1]);
}
int getmax(int v, int tl, int tr, int l, int r) {
    if (l > r) return 0;
    if (tl == l && tr == r)
        return t[v];
    int tm = (tl + tr) / 2;
    return max(getmax(2 * v, tl, tm, l, min(r, tm)),
               getmax(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
void solve() {
    int n, m;
    cin >> n >> m;
    bool ans[m + 1] = {};
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    for (int i = 1; i <= m; i++) {
        cin >> l >> r >> k;
        q[r].pb({l, {k, i}});
    } int f[n + 1]; stack<int> st;
    for (int i = 1; i <= n; i++) {
        while (st.size() && arr[st.top()] <= arr[i]) st.pop();
        if (st.size() == 0) f[i] = 0;
        else f[i] = st.top();
        st.push(i);
    } for (int i = 1; i <= n; i++) {
        if (f[i] != 0) update(1, 1, n, f[i], arr[f[i]] + arr[i]);
        for (auto v : q[i]) {
            ans[v.sc.sc] = (getmax(1, 1, n, v.ff, i) <= v.sc.ff);
        }
    } for (int i = 1; i <= m; i++)
        cout << ans[i] << '\n';
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 6 ms 27224 KB Output is correct
2 Correct 5 ms 25228 KB Output is correct
3 Correct 6 ms 27228 KB Output is correct
4 Correct 6 ms 27328 KB Output is correct
5 Correct 6 ms 27228 KB Output is correct
6 Correct 6 ms 27340 KB Output is correct
7 Correct 6 ms 27224 KB Output is correct
8 Correct 6 ms 25176 KB Output is correct
9 Correct 6 ms 25180 KB Output is correct
10 Correct 6 ms 25180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 27224 KB Output is correct
2 Correct 5 ms 25228 KB Output is correct
3 Correct 6 ms 27228 KB Output is correct
4 Correct 6 ms 27328 KB Output is correct
5 Correct 6 ms 27228 KB Output is correct
6 Correct 6 ms 27340 KB Output is correct
7 Correct 6 ms 27224 KB Output is correct
8 Correct 6 ms 25176 KB Output is correct
9 Correct 6 ms 25180 KB Output is correct
10 Correct 6 ms 25180 KB Output is correct
11 Correct 7 ms 27228 KB Output is correct
12 Correct 8 ms 27320 KB Output is correct
13 Correct 8 ms 27736 KB Output is correct
14 Correct 9 ms 27512 KB Output is correct
15 Correct 9 ms 27484 KB Output is correct
16 Correct 8 ms 25364 KB Output is correct
17 Correct 7 ms 25436 KB Output is correct
18 Correct 8 ms 25468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1062 ms 88392 KB Output is correct
2 Correct 1040 ms 97360 KB Output is correct
3 Correct 1060 ms 98676 KB Output is correct
4 Correct 1038 ms 97528 KB Output is correct
5 Correct 999 ms 90916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 31884 KB Output is correct
2 Correct 81 ms 31872 KB Output is correct
3 Correct 71 ms 29776 KB Output is correct
4 Correct 71 ms 29980 KB Output is correct
5 Correct 68 ms 30036 KB Output is correct
6 Correct 60 ms 31288 KB Output is correct
7 Correct 62 ms 31516 KB Output is correct
8 Correct 60 ms 29408 KB Output is correct
9 Correct 32 ms 28172 KB Output is correct
10 Correct 59 ms 29508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 27224 KB Output is correct
2 Correct 5 ms 25228 KB Output is correct
3 Correct 6 ms 27228 KB Output is correct
4 Correct 6 ms 27328 KB Output is correct
5 Correct 6 ms 27228 KB Output is correct
6 Correct 6 ms 27340 KB Output is correct
7 Correct 6 ms 27224 KB Output is correct
8 Correct 6 ms 25176 KB Output is correct
9 Correct 6 ms 25180 KB Output is correct
10 Correct 6 ms 25180 KB Output is correct
11 Correct 7 ms 27228 KB Output is correct
12 Correct 8 ms 27320 KB Output is correct
13 Correct 8 ms 27736 KB Output is correct
14 Correct 9 ms 27512 KB Output is correct
15 Correct 9 ms 27484 KB Output is correct
16 Correct 8 ms 25364 KB Output is correct
17 Correct 7 ms 25436 KB Output is correct
18 Correct 8 ms 25468 KB Output is correct
19 Correct 182 ms 39884 KB Output is correct
20 Correct 167 ms 40020 KB Output is correct
21 Correct 149 ms 40828 KB Output is correct
22 Correct 155 ms 40788 KB Output is correct
23 Correct 163 ms 40724 KB Output is correct
24 Correct 127 ms 36532 KB Output is correct
25 Correct 128 ms 36460 KB Output is correct
26 Correct 152 ms 36908 KB Output is correct
27 Correct 137 ms 36948 KB Output is correct
28 Correct 152 ms 36968 KB Output is correct
29 Correct 144 ms 37632 KB Output is correct
30 Correct 148 ms 37524 KB Output is correct
31 Correct 171 ms 37200 KB Output is correct
32 Correct 159 ms 37200 KB Output is correct
33 Correct 141 ms 37248 KB Output is correct
34 Correct 119 ms 38232 KB Output is correct
35 Correct 118 ms 38064 KB Output is correct
36 Correct 133 ms 37924 KB Output is correct
37 Correct 117 ms 37972 KB Output is correct
38 Correct 125 ms 38100 KB Output is correct
39 Correct 128 ms 38152 KB Output is correct
40 Correct 99 ms 34312 KB Output is correct
41 Correct 128 ms 35124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 27224 KB Output is correct
2 Correct 5 ms 25228 KB Output is correct
3 Correct 6 ms 27228 KB Output is correct
4 Correct 6 ms 27328 KB Output is correct
5 Correct 6 ms 27228 KB Output is correct
6 Correct 6 ms 27340 KB Output is correct
7 Correct 6 ms 27224 KB Output is correct
8 Correct 6 ms 25176 KB Output is correct
9 Correct 6 ms 25180 KB Output is correct
10 Correct 6 ms 25180 KB Output is correct
11 Correct 7 ms 27228 KB Output is correct
12 Correct 8 ms 27320 KB Output is correct
13 Correct 8 ms 27736 KB Output is correct
14 Correct 9 ms 27512 KB Output is correct
15 Correct 9 ms 27484 KB Output is correct
16 Correct 8 ms 25364 KB Output is correct
17 Correct 7 ms 25436 KB Output is correct
18 Correct 8 ms 25468 KB Output is correct
19 Correct 1062 ms 88392 KB Output is correct
20 Correct 1040 ms 97360 KB Output is correct
21 Correct 1060 ms 98676 KB Output is correct
22 Correct 1038 ms 97528 KB Output is correct
23 Correct 999 ms 90916 KB Output is correct
24 Correct 75 ms 31884 KB Output is correct
25 Correct 81 ms 31872 KB Output is correct
26 Correct 71 ms 29776 KB Output is correct
27 Correct 71 ms 29980 KB Output is correct
28 Correct 68 ms 30036 KB Output is correct
29 Correct 60 ms 31288 KB Output is correct
30 Correct 62 ms 31516 KB Output is correct
31 Correct 60 ms 29408 KB Output is correct
32 Correct 32 ms 28172 KB Output is correct
33 Correct 59 ms 29508 KB Output is correct
34 Correct 182 ms 39884 KB Output is correct
35 Correct 167 ms 40020 KB Output is correct
36 Correct 149 ms 40828 KB Output is correct
37 Correct 155 ms 40788 KB Output is correct
38 Correct 163 ms 40724 KB Output is correct
39 Correct 127 ms 36532 KB Output is correct
40 Correct 128 ms 36460 KB Output is correct
41 Correct 152 ms 36908 KB Output is correct
42 Correct 137 ms 36948 KB Output is correct
43 Correct 152 ms 36968 KB Output is correct
44 Correct 144 ms 37632 KB Output is correct
45 Correct 148 ms 37524 KB Output is correct
46 Correct 171 ms 37200 KB Output is correct
47 Correct 159 ms 37200 KB Output is correct
48 Correct 141 ms 37248 KB Output is correct
49 Correct 119 ms 38232 KB Output is correct
50 Correct 118 ms 38064 KB Output is correct
51 Correct 133 ms 37924 KB Output is correct
52 Correct 117 ms 37972 KB Output is correct
53 Correct 125 ms 38100 KB Output is correct
54 Correct 128 ms 38152 KB Output is correct
55 Correct 99 ms 34312 KB Output is correct
56 Correct 128 ms 35124 KB Output is correct
57 Correct 980 ms 97700 KB Output is correct
58 Correct 1039 ms 97684 KB Output is correct
59 Correct 1026 ms 96132 KB Output is correct
60 Correct 978 ms 95808 KB Output is correct
61 Correct 975 ms 96152 KB Output is correct
62 Correct 987 ms 96108 KB Output is correct
63 Correct 635 ms 86176 KB Output is correct
64 Correct 622 ms 86196 KB Output is correct
65 Correct 850 ms 89696 KB Output is correct
66 Correct 803 ms 89168 KB Output is correct
67 Correct 828 ms 89240 KB Output is correct
68 Correct 892 ms 90900 KB Output is correct
69 Correct 909 ms 90976 KB Output is correct
70 Correct 966 ms 90480 KB Output is correct
71 Correct 889 ms 90600 KB Output is correct
72 Correct 906 ms 90836 KB Output is correct
73 Correct 612 ms 84060 KB Output is correct
74 Correct 579 ms 84996 KB Output is correct
75 Correct 582 ms 83924 KB Output is correct
76 Correct 575 ms 84308 KB Output is correct
77 Correct 570 ms 83792 KB Output is correct
78 Correct 765 ms 86180 KB Output is correct
79 Correct 547 ms 72356 KB Output is correct
80 Correct 772 ms 81036 KB Output is correct