Submission #167230

# Submission time Handle Problem Language Result Execution time Memory
167230 2019-12-06T20:59:37 Z apostoldaniel854 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
963 ms 94980 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\n"
typedef long long ll;

int n, m;

const int N = 1e6;

int w[1 + N];
int stk[1 + N];
vector <int> op[1 + N];

void prec () {
    int top = 0;
    for (int i = 1; i <= n; i++) {
        while (top && w[stk[top]] <= w[i])
            top--;
        if (top)
            op[stk[top]].pb (i);
        stk[++top] = i;
    }
}
struct Query {
    int l;
    int r;
    int mood;
    int index;
};

Query q[1 + N];

bool cmp (Query a, Query b) {
    return a.l > b.l;
}

int lsb (int x) {
    return x & -x;
}

int aib[1 + N];
int ans[1 + N];



void upd (int pos, int val) {
    while (pos <= n) {
        aib[pos] = max (aib[pos], val);
        pos += lsb (pos);
    }
}

int qry (int pos) {
    int ans = 0;
    while (pos) {
        ans = max (ans, aib[pos]);
        pos -= lsb (pos);
    }
    return ans;
}

int main () {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);

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

    prec ();

    for (int i = 1; i <= m; i++) {
        cin >> q[i].l >> q[i].r >> q[i].mood;
        q[i].index = i;
    }

    sort (q + 1, q + m + 1, cmp);

    int l = n;
    for (int i = 1; i <= m; i++) {
        while (l >= q[i].l) {
            for (auto x : op[l])
                upd (x, w[x] + w[l]);
            l--;
        }
        ans[q[i].index] = (qry (q[i].r) <= q[i].mood);
    }

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

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 29 ms 23928 KB Output is correct
2 Correct 24 ms 23900 KB Output is correct
3 Correct 25 ms 23800 KB Output is correct
4 Correct 25 ms 23800 KB Output is correct
5 Correct 25 ms 23800 KB Output is correct
6 Correct 25 ms 23928 KB Output is correct
7 Correct 26 ms 23928 KB Output is correct
8 Correct 25 ms 23900 KB Output is correct
9 Correct 26 ms 23796 KB Output is correct
10 Correct 25 ms 23932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 23928 KB Output is correct
2 Correct 24 ms 23900 KB Output is correct
3 Correct 25 ms 23800 KB Output is correct
4 Correct 25 ms 23800 KB Output is correct
5 Correct 25 ms 23800 KB Output is correct
6 Correct 25 ms 23928 KB Output is correct
7 Correct 26 ms 23928 KB Output is correct
8 Correct 25 ms 23900 KB Output is correct
9 Correct 26 ms 23796 KB Output is correct
10 Correct 25 ms 23932 KB Output is correct
11 Correct 28 ms 24056 KB Output is correct
12 Correct 28 ms 24184 KB Output is correct
13 Correct 27 ms 24184 KB Output is correct
14 Correct 31 ms 24312 KB Output is correct
15 Correct 29 ms 24312 KB Output is correct
16 Correct 28 ms 24188 KB Output is correct
17 Correct 29 ms 24056 KB Output is correct
18 Correct 30 ms 24056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 962 ms 69376 KB Output is correct
2 Correct 934 ms 69624 KB Output is correct
3 Correct 933 ms 69528 KB Output is correct
4 Correct 939 ms 69508 KB Output is correct
5 Correct 771 ms 49512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 28408 KB Output is correct
2 Correct 99 ms 30352 KB Output is correct
3 Correct 88 ms 28408 KB Output is correct
4 Correct 89 ms 28436 KB Output is correct
5 Correct 89 ms 28408 KB Output is correct
6 Correct 82 ms 28408 KB Output is correct
7 Correct 82 ms 28408 KB Output is correct
8 Correct 84 ms 28792 KB Output is correct
9 Correct 68 ms 27000 KB Output is correct
10 Correct 84 ms 28408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 23928 KB Output is correct
2 Correct 24 ms 23900 KB Output is correct
3 Correct 25 ms 23800 KB Output is correct
4 Correct 25 ms 23800 KB Output is correct
5 Correct 25 ms 23800 KB Output is correct
6 Correct 25 ms 23928 KB Output is correct
7 Correct 26 ms 23928 KB Output is correct
8 Correct 25 ms 23900 KB Output is correct
9 Correct 26 ms 23796 KB Output is correct
10 Correct 25 ms 23932 KB Output is correct
11 Correct 28 ms 24056 KB Output is correct
12 Correct 28 ms 24184 KB Output is correct
13 Correct 27 ms 24184 KB Output is correct
14 Correct 31 ms 24312 KB Output is correct
15 Correct 29 ms 24312 KB Output is correct
16 Correct 28 ms 24188 KB Output is correct
17 Correct 29 ms 24056 KB Output is correct
18 Correct 30 ms 24056 KB Output is correct
19 Correct 209 ms 39656 KB Output is correct
20 Correct 208 ms 39672 KB Output is correct
21 Correct 196 ms 39416 KB Output is correct
22 Correct 199 ms 39472 KB Output is correct
23 Correct 198 ms 39416 KB Output is correct
24 Correct 166 ms 35364 KB Output is correct
25 Correct 166 ms 35260 KB Output is correct
26 Correct 171 ms 35520 KB Output is correct
27 Correct 174 ms 35516 KB Output is correct
28 Correct 171 ms 35576 KB Output is correct
29 Correct 175 ms 35616 KB Output is correct
30 Correct 177 ms 35812 KB Output is correct
31 Correct 177 ms 35552 KB Output is correct
32 Correct 175 ms 35576 KB Output is correct
33 Correct 184 ms 35756 KB Output is correct
34 Correct 161 ms 35192 KB Output is correct
35 Correct 179 ms 35192 KB Output is correct
36 Correct 159 ms 35128 KB Output is correct
37 Correct 160 ms 35112 KB Output is correct
38 Correct 162 ms 35192 KB Output is correct
39 Correct 168 ms 35548 KB Output is correct
40 Correct 149 ms 33528 KB Output is correct
41 Correct 157 ms 34904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 23928 KB Output is correct
2 Correct 24 ms 23900 KB Output is correct
3 Correct 25 ms 23800 KB Output is correct
4 Correct 25 ms 23800 KB Output is correct
5 Correct 25 ms 23800 KB Output is correct
6 Correct 25 ms 23928 KB Output is correct
7 Correct 26 ms 23928 KB Output is correct
8 Correct 25 ms 23900 KB Output is correct
9 Correct 26 ms 23796 KB Output is correct
10 Correct 25 ms 23932 KB Output is correct
11 Correct 28 ms 24056 KB Output is correct
12 Correct 28 ms 24184 KB Output is correct
13 Correct 27 ms 24184 KB Output is correct
14 Correct 31 ms 24312 KB Output is correct
15 Correct 29 ms 24312 KB Output is correct
16 Correct 28 ms 24188 KB Output is correct
17 Correct 29 ms 24056 KB Output is correct
18 Correct 30 ms 24056 KB Output is correct
19 Correct 962 ms 69376 KB Output is correct
20 Correct 934 ms 69624 KB Output is correct
21 Correct 933 ms 69528 KB Output is correct
22 Correct 939 ms 69508 KB Output is correct
23 Correct 771 ms 49512 KB Output is correct
24 Correct 103 ms 28408 KB Output is correct
25 Correct 99 ms 30352 KB Output is correct
26 Correct 88 ms 28408 KB Output is correct
27 Correct 89 ms 28436 KB Output is correct
28 Correct 89 ms 28408 KB Output is correct
29 Correct 82 ms 28408 KB Output is correct
30 Correct 82 ms 28408 KB Output is correct
31 Correct 84 ms 28792 KB Output is correct
32 Correct 68 ms 27000 KB Output is correct
33 Correct 84 ms 28408 KB Output is correct
34 Correct 209 ms 39656 KB Output is correct
35 Correct 208 ms 39672 KB Output is correct
36 Correct 196 ms 39416 KB Output is correct
37 Correct 199 ms 39472 KB Output is correct
38 Correct 198 ms 39416 KB Output is correct
39 Correct 166 ms 35364 KB Output is correct
40 Correct 166 ms 35260 KB Output is correct
41 Correct 171 ms 35520 KB Output is correct
42 Correct 174 ms 35516 KB Output is correct
43 Correct 171 ms 35576 KB Output is correct
44 Correct 175 ms 35616 KB Output is correct
45 Correct 177 ms 35812 KB Output is correct
46 Correct 177 ms 35552 KB Output is correct
47 Correct 175 ms 35576 KB Output is correct
48 Correct 184 ms 35756 KB Output is correct
49 Correct 161 ms 35192 KB Output is correct
50 Correct 179 ms 35192 KB Output is correct
51 Correct 159 ms 35128 KB Output is correct
52 Correct 160 ms 35112 KB Output is correct
53 Correct 162 ms 35192 KB Output is correct
54 Correct 168 ms 35548 KB Output is correct
55 Correct 149 ms 33528 KB Output is correct
56 Correct 157 ms 34904 KB Output is correct
57 Correct 952 ms 94948 KB Output is correct
58 Correct 963 ms 94980 KB Output is correct
59 Correct 941 ms 94968 KB Output is correct
60 Correct 930 ms 94812 KB Output is correct
61 Correct 952 ms 94756 KB Output is correct
62 Correct 942 ms 94768 KB Output is correct
63 Correct 764 ms 73592 KB Output is correct
64 Correct 858 ms 73464 KB Output is correct
65 Correct 825 ms 74344 KB Output is correct
66 Correct 802 ms 74604 KB Output is correct
67 Correct 841 ms 74108 KB Output is correct
68 Correct 795 ms 73392 KB Output is correct
69 Correct 789 ms 71688 KB Output is correct
70 Correct 790 ms 70588 KB Output is correct
71 Correct 789 ms 68872 KB Output is correct
72 Correct 793 ms 69872 KB Output is correct
73 Correct 709 ms 67244 KB Output is correct
74 Correct 710 ms 63768 KB Output is correct
75 Correct 706 ms 60832 KB Output is correct
76 Correct 703 ms 63092 KB Output is correct
77 Correct 908 ms 66000 KB Output is correct
78 Correct 772 ms 76104 KB Output is correct
79 Correct 634 ms 65808 KB Output is correct
80 Correct 825 ms 72408 KB Output is correct