Submission #501785

# Submission time Handle Problem Language Result Execution time Memory
501785 2022-01-04T14:49:54 Z dxz05 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
651 ms 114996 KB
//#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << "[" << H << "]";
    debug_out(T...);
}

#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

clock_t startTime;

double getCurrentTime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}

#define MP make_pair

typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.000001;
const int MOD = 998244353;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 3e2;
const int M = 1222;

int t[N];

void update(int v, int tl, int tr, int pos, int val){
    if (tl == tr){
        t[v] = max(t[v], val);
        return;
    }
    int tm = (tl + tr) >> 1;
    if (pos <= tm) update(v + v, tl, tm, pos, val); else
        update(v + v + 1, tm + 1, tr, pos, val);

    t[v] = max(t[v + v], t[v + v + 1]);
}

int get(int v, int tl, int tr, int l, int r){
    if (l <= tl && tr <= r) return t[v];
    if (tl > r || tr < l) return 0;
    int tm = (tl + tr) >> 1;
    return max(get(v + v, tl, tm, l, r), get(v + v + 1, tm + 1, tr, l, r));
}

int a[N];
vector<pair<int, pair<int, int>>> queries[N];

void solve(int TC) {
    int n, q;
    cin >> n >> q;

    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }

    for (int i = 1; i <= q; i++){
        int l, r, k;
        cin >> l >> r >> k;
        queries[r].emplace_back(l, MP(k, i));
    }

    bitset<200001> ans;

    a[0] = INF;
    stack<int> st;
    st.push(0);
    for (int i = 1; i <= n; i++){
        while (!st.empty() && a[st.top()] <= a[i]) st.pop();
        int j = st.top();
        if (j != 0) update(1, 1, n, j, a[j] + a[i]);

        for (auto qu : queries[i]){
            int l = qu.first, k = qu.second.first, ind = qu.second.second;
            ans[ind] = get(1, 1, n, l, i) <= k;
        }

        st.push(i);
    }

    for (int i = 1; i <= q; i++) cout << ans[i] << '\n';

}

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

#ifdef dddxxz
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int TC = 1;
//    cin >> TC;

    for (int test = 1; test <= TC; test++) {
        //debug(test);
        //cout << "Case #" << test << ": ";
        solve(test);
    }

    cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23816 KB Output is correct
2 Correct 15 ms 23728 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 13 ms 23848 KB Output is correct
5 Correct 13 ms 23816 KB Output is correct
6 Correct 14 ms 23844 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 13 ms 23840 KB Output is correct
9 Correct 13 ms 23836 KB Output is correct
10 Correct 13 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23816 KB Output is correct
2 Correct 15 ms 23728 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 13 ms 23848 KB Output is correct
5 Correct 13 ms 23816 KB Output is correct
6 Correct 14 ms 23844 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 13 ms 23840 KB Output is correct
9 Correct 13 ms 23836 KB Output is correct
10 Correct 13 ms 23756 KB Output is correct
11 Correct 15 ms 23896 KB Output is correct
12 Correct 17 ms 24012 KB Output is correct
13 Correct 17 ms 24004 KB Output is correct
14 Correct 17 ms 24180 KB Output is correct
15 Correct 17 ms 24172 KB Output is correct
16 Correct 16 ms 24064 KB Output is correct
17 Correct 15 ms 23972 KB Output is correct
18 Correct 16 ms 24080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 651 ms 114996 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 29496 KB Output is correct
2 Correct 91 ms 29276 KB Output is correct
3 Correct 82 ms 28352 KB Output is correct
4 Correct 87 ms 28404 KB Output is correct
5 Correct 88 ms 28444 KB Output is correct
6 Correct 80 ms 27936 KB Output is correct
7 Correct 75 ms 27940 KB Output is correct
8 Correct 89 ms 28124 KB Output is correct
9 Correct 47 ms 26844 KB Output is correct
10 Correct 81 ms 28184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23816 KB Output is correct
2 Correct 15 ms 23728 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 13 ms 23848 KB Output is correct
5 Correct 13 ms 23816 KB Output is correct
6 Correct 14 ms 23844 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 13 ms 23840 KB Output is correct
9 Correct 13 ms 23836 KB Output is correct
10 Correct 13 ms 23756 KB Output is correct
11 Correct 15 ms 23896 KB Output is correct
12 Correct 17 ms 24012 KB Output is correct
13 Correct 17 ms 24004 KB Output is correct
14 Correct 17 ms 24180 KB Output is correct
15 Correct 17 ms 24172 KB Output is correct
16 Correct 16 ms 24064 KB Output is correct
17 Correct 15 ms 23972 KB Output is correct
18 Correct 16 ms 24080 KB Output is correct
19 Correct 230 ms 36176 KB Output is correct
20 Correct 242 ms 36028 KB Output is correct
21 Correct 207 ms 35440 KB Output is correct
22 Correct 197 ms 35648 KB Output is correct
23 Correct 223 ms 35644 KB Output is correct
24 Correct 160 ms 33436 KB Output is correct
25 Correct 174 ms 33568 KB Output is correct
26 Correct 189 ms 33732 KB Output is correct
27 Correct 180 ms 33780 KB Output is correct
28 Correct 204 ms 33772 KB Output is correct
29 Correct 191 ms 33916 KB Output is correct
30 Correct 213 ms 34192 KB Output is correct
31 Correct 199 ms 34116 KB Output is correct
32 Correct 221 ms 34000 KB Output is correct
33 Correct 244 ms 34124 KB Output is correct
34 Correct 157 ms 33084 KB Output is correct
35 Correct 168 ms 33280 KB Output is correct
36 Correct 156 ms 33220 KB Output is correct
37 Correct 170 ms 33216 KB Output is correct
38 Correct 165 ms 33308 KB Output is correct
39 Correct 178 ms 34484 KB Output is correct
40 Correct 179 ms 32752 KB Output is correct
41 Correct 169 ms 33872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23816 KB Output is correct
2 Correct 15 ms 23728 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 13 ms 23848 KB Output is correct
5 Correct 13 ms 23816 KB Output is correct
6 Correct 14 ms 23844 KB Output is correct
7 Correct 12 ms 23764 KB Output is correct
8 Correct 13 ms 23840 KB Output is correct
9 Correct 13 ms 23836 KB Output is correct
10 Correct 13 ms 23756 KB Output is correct
11 Correct 15 ms 23896 KB Output is correct
12 Correct 17 ms 24012 KB Output is correct
13 Correct 17 ms 24004 KB Output is correct
14 Correct 17 ms 24180 KB Output is correct
15 Correct 17 ms 24172 KB Output is correct
16 Correct 16 ms 24064 KB Output is correct
17 Correct 15 ms 23972 KB Output is correct
18 Correct 16 ms 24080 KB Output is correct
19 Runtime error 651 ms 114996 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -