Submission #1018049

# Submission time Handle Problem Language Result Execution time Memory
1018049 2024-07-09T13:17:02 Z codefox Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2919 ms 230296 KB
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#define pii pair<int, int>
#define pipi pair<pii, pii>

const int N = 1<<20;
int bin[2*N];
vector<int> bmm[2*N];
int sol = 0;

int query(int curr, int l, int r, int a, int b, int mx)
{
    if (l >= b || r <= a) return -1e9;
    if (a <= l && r <= b)
    {
        sol = max(sol, bin[curr]);
        auto u = lower_bound(bmm[curr].begin(), bmm[curr].end(), mx);
        if (u!= bmm[curr].begin())
        {
            int last = *(--u);
            sol = max(sol, mx+last);
        }
        return bmm[curr].back();
    }
    int m = (l+r)/2;
    mx = max(mx, query(curr*2, l, m, a, b, mx));
    mx = max(mx, query(curr*2+1, m, r, a, b, mx));
    return mx;
}

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

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

    for (int i = 0; i < 2*N;i ++) bin[i]=0;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        bmm[i+N].push_back(a);
    }
    for (int i = n; i < N; i++) bmm[i+N].push_back(1e9);
    for (int i = N-1; i >0; i--)
    {
        bmm[i] = vector<int>(bmm[i*2]);
        for (int ele:bmm[i*2+1]) bmm[i].push_back(ele);
        sort(bmm[i].begin(), bmm[i].end());
        bin[i] = max(bin[i*2], bin[i*2+1]);
        int mx = bmm[i*2].back();
        auto u = lower_bound(bmm[i*2+1].begin(), bmm[i*2+1].end(), mx);
        if (u!=bmm[i*2+1].begin())
        {
            bin[i] = max(bin[i], mx+*(--u));
        }
    }

    while(q--)
    {
        int l, r, mood;
        cin >> l >> r >> mood;
        l--;
        sol=0;
        query(1, 0, N, l, r, -1e9);
        if (sol <= mood) cout << "1\n";
        else cout << "0\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 298 ms 194896 KB Output is correct
2 Correct 289 ms 194628 KB Output is correct
3 Correct 288 ms 194628 KB Output is correct
4 Correct 289 ms 194632 KB Output is correct
5 Correct 325 ms 194628 KB Output is correct
6 Correct 294 ms 194552 KB Output is correct
7 Correct 286 ms 194632 KB Output is correct
8 Correct 309 ms 194632 KB Output is correct
9 Correct 284 ms 194632 KB Output is correct
10 Correct 289 ms 194480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 298 ms 194896 KB Output is correct
2 Correct 289 ms 194628 KB Output is correct
3 Correct 288 ms 194628 KB Output is correct
4 Correct 289 ms 194632 KB Output is correct
5 Correct 325 ms 194628 KB Output is correct
6 Correct 294 ms 194552 KB Output is correct
7 Correct 286 ms 194632 KB Output is correct
8 Correct 309 ms 194632 KB Output is correct
9 Correct 284 ms 194632 KB Output is correct
10 Correct 289 ms 194480 KB Output is correct
11 Correct 288 ms 194668 KB Output is correct
12 Correct 293 ms 194628 KB Output is correct
13 Correct 297 ms 194684 KB Output is correct
14 Correct 305 ms 194632 KB Output is correct
15 Correct 304 ms 194688 KB Output is correct
16 Correct 321 ms 194632 KB Output is correct
17 Correct 304 ms 194664 KB Output is correct
18 Correct 329 ms 195868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2892 ms 205376 KB Output is correct
2 Correct 2850 ms 229420 KB Output is correct
3 Correct 2774 ms 229408 KB Output is correct
4 Correct 2919 ms 229424 KB Output is correct
5 Correct 2141 ms 229320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 431 ms 194876 KB Output is correct
2 Correct 402 ms 194880 KB Output is correct
3 Correct 416 ms 195912 KB Output is correct
4 Correct 396 ms 194884 KB Output is correct
5 Correct 415 ms 194660 KB Output is correct
6 Correct 405 ms 195396 KB Output is correct
7 Correct 412 ms 195676 KB Output is correct
8 Correct 439 ms 194888 KB Output is correct
9 Correct 382 ms 196424 KB Output is correct
10 Correct 397 ms 194896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 298 ms 194896 KB Output is correct
2 Correct 289 ms 194628 KB Output is correct
3 Correct 288 ms 194628 KB Output is correct
4 Correct 289 ms 194632 KB Output is correct
5 Correct 325 ms 194628 KB Output is correct
6 Correct 294 ms 194552 KB Output is correct
7 Correct 286 ms 194632 KB Output is correct
8 Correct 309 ms 194632 KB Output is correct
9 Correct 284 ms 194632 KB Output is correct
10 Correct 289 ms 194480 KB Output is correct
11 Correct 288 ms 194668 KB Output is correct
12 Correct 293 ms 194628 KB Output is correct
13 Correct 297 ms 194684 KB Output is correct
14 Correct 305 ms 194632 KB Output is correct
15 Correct 304 ms 194688 KB Output is correct
16 Correct 321 ms 194632 KB Output is correct
17 Correct 304 ms 194664 KB Output is correct
18 Correct 329 ms 195868 KB Output is correct
19 Correct 648 ms 194884 KB Output is correct
20 Correct 647 ms 194840 KB Output is correct
21 Correct 607 ms 195040 KB Output is correct
22 Correct 577 ms 194868 KB Output is correct
23 Correct 584 ms 195400 KB Output is correct
24 Correct 449 ms 195328 KB Output is correct
25 Correct 466 ms 196164 KB Output is correct
26 Correct 524 ms 195928 KB Output is correct
27 Correct 508 ms 194888 KB Output is correct
28 Correct 504 ms 194884 KB Output is correct
29 Correct 489 ms 195656 KB Output is correct
30 Correct 569 ms 194948 KB Output is correct
31 Correct 507 ms 196424 KB Output is correct
32 Correct 508 ms 195400 KB Output is correct
33 Correct 492 ms 195140 KB Output is correct
34 Correct 443 ms 196128 KB Output is correct
35 Correct 452 ms 195136 KB Output is correct
36 Correct 435 ms 195544 KB Output is correct
37 Correct 429 ms 195504 KB Output is correct
38 Correct 473 ms 194884 KB Output is correct
39 Correct 484 ms 195360 KB Output is correct
40 Correct 403 ms 195400 KB Output is correct
41 Correct 444 ms 195656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 298 ms 194896 KB Output is correct
2 Correct 289 ms 194628 KB Output is correct
3 Correct 288 ms 194628 KB Output is correct
4 Correct 289 ms 194632 KB Output is correct
5 Correct 325 ms 194628 KB Output is correct
6 Correct 294 ms 194552 KB Output is correct
7 Correct 286 ms 194632 KB Output is correct
8 Correct 309 ms 194632 KB Output is correct
9 Correct 284 ms 194632 KB Output is correct
10 Correct 289 ms 194480 KB Output is correct
11 Correct 288 ms 194668 KB Output is correct
12 Correct 293 ms 194628 KB Output is correct
13 Correct 297 ms 194684 KB Output is correct
14 Correct 305 ms 194632 KB Output is correct
15 Correct 304 ms 194688 KB Output is correct
16 Correct 321 ms 194632 KB Output is correct
17 Correct 304 ms 194664 KB Output is correct
18 Correct 329 ms 195868 KB Output is correct
19 Correct 2892 ms 205376 KB Output is correct
20 Correct 2850 ms 229420 KB Output is correct
21 Correct 2774 ms 229408 KB Output is correct
22 Correct 2919 ms 229424 KB Output is correct
23 Correct 2141 ms 229320 KB Output is correct
24 Correct 431 ms 194876 KB Output is correct
25 Correct 402 ms 194880 KB Output is correct
26 Correct 416 ms 195912 KB Output is correct
27 Correct 396 ms 194884 KB Output is correct
28 Correct 415 ms 194660 KB Output is correct
29 Correct 405 ms 195396 KB Output is correct
30 Correct 412 ms 195676 KB Output is correct
31 Correct 439 ms 194888 KB Output is correct
32 Correct 382 ms 196424 KB Output is correct
33 Correct 397 ms 194896 KB Output is correct
34 Correct 648 ms 194884 KB Output is correct
35 Correct 647 ms 194840 KB Output is correct
36 Correct 607 ms 195040 KB Output is correct
37 Correct 577 ms 194868 KB Output is correct
38 Correct 584 ms 195400 KB Output is correct
39 Correct 449 ms 195328 KB Output is correct
40 Correct 466 ms 196164 KB Output is correct
41 Correct 524 ms 195928 KB Output is correct
42 Correct 508 ms 194888 KB Output is correct
43 Correct 504 ms 194884 KB Output is correct
44 Correct 489 ms 195656 KB Output is correct
45 Correct 569 ms 194948 KB Output is correct
46 Correct 507 ms 196424 KB Output is correct
47 Correct 508 ms 195400 KB Output is correct
48 Correct 492 ms 195140 KB Output is correct
49 Correct 443 ms 196128 KB Output is correct
50 Correct 452 ms 195136 KB Output is correct
51 Correct 435 ms 195544 KB Output is correct
52 Correct 429 ms 195504 KB Output is correct
53 Correct 473 ms 194884 KB Output is correct
54 Correct 484 ms 195360 KB Output is correct
55 Correct 403 ms 195400 KB Output is correct
56 Correct 444 ms 195656 KB Output is correct
57 Correct 2613 ms 230128 KB Output is correct
58 Correct 2619 ms 230104 KB Output is correct
59 Correct 2368 ms 230152 KB Output is correct
60 Correct 2537 ms 230080 KB Output is correct
61 Correct 2515 ms 229972 KB Output is correct
62 Correct 2568 ms 230128 KB Output is correct
63 Correct 1166 ms 228320 KB Output is correct
64 Correct 1186 ms 228336 KB Output is correct
65 Correct 1942 ms 230124 KB Output is correct
66 Correct 1913 ms 230096 KB Output is correct
67 Correct 1945 ms 229956 KB Output is correct
68 Correct 2087 ms 230120 KB Output is correct
69 Correct 1906 ms 230296 KB Output is correct
70 Correct 1978 ms 230144 KB Output is correct
71 Correct 1905 ms 230132 KB Output is correct
72 Correct 1940 ms 230192 KB Output is correct
73 Correct 1119 ms 226712 KB Output is correct
74 Correct 1113 ms 227652 KB Output is correct
75 Correct 1146 ms 226776 KB Output is correct
76 Correct 1112 ms 226880 KB Output is correct
77 Correct 1128 ms 226812 KB Output is correct
78 Correct 1742 ms 223632 KB Output is correct
79 Correct 1107 ms 219120 KB Output is correct
80 Correct 1557 ms 221268 KB Output is correct