Submission #1017931

# Submission time Handle Problem Language Result Execution time Memory
1017931 2024-07-09T11:36:15 Z codefox Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
34 / 100
676 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

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

int N = 1<<19;
//20? maybe 18
vector<int> bin(2*N, 0);
vector<set<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]);
        if (bmm[curr].lower_bound(mx)!= bmm[curr].begin())
        {
            int last = *(--bmm[curr].lower_bound(mx));
            sol = max(sol, mx+last);
        }
        return *(--bmm[curr].end());
    }
    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()
{
    int n, q;
    cin >> n >> q;

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

    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 72 ms 102996 KB Output is correct
2 Correct 64 ms 102992 KB Output is correct
3 Correct 86 ms 103048 KB Output is correct
4 Correct 66 ms 102996 KB Output is correct
5 Correct 88 ms 102996 KB Output is correct
6 Correct 71 ms 103396 KB Output is correct
7 Correct 72 ms 103252 KB Output is correct
8 Correct 66 ms 103252 KB Output is correct
9 Correct 73 ms 103136 KB Output is correct
10 Correct 69 ms 102992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 102996 KB Output is correct
2 Correct 64 ms 102992 KB Output is correct
3 Correct 86 ms 103048 KB Output is correct
4 Correct 66 ms 102996 KB Output is correct
5 Correct 88 ms 102996 KB Output is correct
6 Correct 71 ms 103396 KB Output is correct
7 Correct 72 ms 103252 KB Output is correct
8 Correct 66 ms 103252 KB Output is correct
9 Correct 73 ms 103136 KB Output is correct
10 Correct 69 ms 102992 KB Output is correct
11 Correct 75 ms 104100 KB Output is correct
12 Correct 85 ms 107052 KB Output is correct
13 Correct 90 ms 107352 KB Output is correct
14 Correct 131 ms 107344 KB Output is correct
15 Correct 90 ms 107344 KB Output is correct
16 Correct 87 ms 107168 KB Output is correct
17 Correct 80 ms 106576 KB Output is correct
18 Correct 82 ms 102932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 218 ms 163924 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 676 ms 147860 KB Output is correct
2 Correct 554 ms 147928 KB Output is correct
3 Correct 351 ms 106064 KB Output is correct
4 Correct 355 ms 106064 KB Output is correct
5 Correct 339 ms 106044 KB Output is correct
6 Correct 316 ms 105684 KB Output is correct
7 Correct 318 ms 105896 KB Output is correct
8 Correct 317 ms 104804 KB Output is correct
9 Correct 241 ms 104960 KB Output is correct
10 Correct 308 ms 105004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 102996 KB Output is correct
2 Correct 64 ms 102992 KB Output is correct
3 Correct 86 ms 103048 KB Output is correct
4 Correct 66 ms 102996 KB Output is correct
5 Correct 88 ms 102996 KB Output is correct
6 Correct 71 ms 103396 KB Output is correct
7 Correct 72 ms 103252 KB Output is correct
8 Correct 66 ms 103252 KB Output is correct
9 Correct 73 ms 103136 KB Output is correct
10 Correct 69 ms 102992 KB Output is correct
11 Correct 75 ms 104100 KB Output is correct
12 Correct 85 ms 107052 KB Output is correct
13 Correct 90 ms 107352 KB Output is correct
14 Correct 131 ms 107344 KB Output is correct
15 Correct 90 ms 107344 KB Output is correct
16 Correct 87 ms 107168 KB Output is correct
17 Correct 80 ms 106576 KB Output is correct
18 Correct 82 ms 102932 KB Output is correct
19 Runtime error 440 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 102996 KB Output is correct
2 Correct 64 ms 102992 KB Output is correct
3 Correct 86 ms 103048 KB Output is correct
4 Correct 66 ms 102996 KB Output is correct
5 Correct 88 ms 102996 KB Output is correct
6 Correct 71 ms 103396 KB Output is correct
7 Correct 72 ms 103252 KB Output is correct
8 Correct 66 ms 103252 KB Output is correct
9 Correct 73 ms 103136 KB Output is correct
10 Correct 69 ms 102992 KB Output is correct
11 Correct 75 ms 104100 KB Output is correct
12 Correct 85 ms 107052 KB Output is correct
13 Correct 90 ms 107352 KB Output is correct
14 Correct 131 ms 107344 KB Output is correct
15 Correct 90 ms 107344 KB Output is correct
16 Correct 87 ms 107168 KB Output is correct
17 Correct 80 ms 106576 KB Output is correct
18 Correct 82 ms 102932 KB Output is correct
19 Runtime error 218 ms 163924 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -