Submission #502671

# Submission time Handle Problem Language Result Execution time Memory
502671 2022-01-06T12:22:16 Z tim Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
1132 ms 229324 KB
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define y1 tim
#define endl "\n"
 
#define sz(x) (long long)(x).size()
#define all(x) (x).begin(), (x).end()
 
using namespace std;
 
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
 
int w[1000010], mx[1000010], ans[1000010], Max, y, l, r, k, n, m;
multiset <int> st[1000010];
 
void build (int l, int r, int x)
{
    if (r < l) return;
    if (l == r)
    {
        mx[x] = w[l];
        st[x].insert(w[l]);
        ans[x] = 0;
        return;
    }
    build (l, (l + r) / 2, x * 2);
    build ((l + r) / 2 + 1, r, x * 2 + 1);
    mx[x] = max (mx[x * 2], mx[x * 2 + 1]);
    ans[x] = max (ans[x * 2], ans[x * 2 + 1]);
    st[x] = st[x * 2];
    int mx1 = -1;
    for (auto i = st[x * 2 + 1].begin(); i != st[x * 2 + 1].end(); i++)
    {
 
        if (*i < mx[x * 2]) mx1 = *i;
        st[x].insert(*i);
    }
    if (mx1 != -1) ans[x] = max (ans[x], mx[x * 2] + mx1);
}
 
void get (int l, int r, int tl, int tr, int x)
{
    if (r < l) return;
    if (tl > r) return;
    if (tr < l) return;
    tl = max (l, tl);
    tr = min (r, tr);
    if (l == tl and r == tr)
    {
        if (Max == 0 and y == 0)
        {
            y = ans[x];
            Max = mx[x];
        }
        else
        {
            y = max (y, ans[x]);
            auto it = st[x].lower_bound(Max);
            if (it != st[x].begin())
            {
                it--;
                y = max (y, Max + *it);
            }
            Max = max (Max, mx[x]);
        }
        return;
    }
    get (l, (l + r) / 2, tl, tr, x * 2);
    get ((l + r) / 2 + 1, r, tl, tr, x * 2 + 1);
}
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> w[i];
    build (1, n, 1);
    for (int i = 1; i <= m; i++)
    {
        cin >> l >> r >> k;
        y = 0;
        Max = 0;
        get (1, n, l, r, 1);
        if (y <= k) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47284 KB Output is correct
2 Correct 30 ms 47236 KB Output is correct
3 Correct 25 ms 47312 KB Output is correct
4 Correct 23 ms 47324 KB Output is correct
5 Correct 24 ms 47292 KB Output is correct
6 Correct 24 ms 47476 KB Output is correct
7 Correct 25 ms 47532 KB Output is correct
8 Correct 24 ms 47612 KB Output is correct
9 Correct 25 ms 47424 KB Output is correct
10 Correct 25 ms 47436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47284 KB Output is correct
2 Correct 30 ms 47236 KB Output is correct
3 Correct 25 ms 47312 KB Output is correct
4 Correct 23 ms 47324 KB Output is correct
5 Correct 24 ms 47292 KB Output is correct
6 Correct 24 ms 47476 KB Output is correct
7 Correct 25 ms 47532 KB Output is correct
8 Correct 24 ms 47612 KB Output is correct
9 Correct 25 ms 47424 KB Output is correct
10 Correct 25 ms 47436 KB Output is correct
11 Correct 29 ms 48068 KB Output is correct
12 Correct 35 ms 50496 KB Output is correct
13 Correct 33 ms 50588 KB Output is correct
14 Correct 37 ms 50748 KB Output is correct
15 Correct 36 ms 50740 KB Output is correct
16 Correct 33 ms 50692 KB Output is correct
17 Correct 31 ms 49972 KB Output is correct
18 Correct 32 ms 50632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 206 ms 157456 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 496 ms 133128 KB Output is correct
2 Correct 406 ms 133996 KB Output is correct
3 Correct 430 ms 133776 KB Output is correct
4 Correct 437 ms 133748 KB Output is correct
5 Correct 420 ms 133784 KB Output is correct
6 Correct 313 ms 133828 KB Output is correct
7 Correct 290 ms 133716 KB Output is correct
8 Correct 454 ms 133776 KB Output is correct
9 Correct 61 ms 48448 KB Output is correct
10 Correct 434 ms 133692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47284 KB Output is correct
2 Correct 30 ms 47236 KB Output is correct
3 Correct 25 ms 47312 KB Output is correct
4 Correct 23 ms 47324 KB Output is correct
5 Correct 24 ms 47292 KB Output is correct
6 Correct 24 ms 47476 KB Output is correct
7 Correct 25 ms 47532 KB Output is correct
8 Correct 24 ms 47612 KB Output is correct
9 Correct 25 ms 47424 KB Output is correct
10 Correct 25 ms 47436 KB Output is correct
11 Correct 29 ms 48068 KB Output is correct
12 Correct 35 ms 50496 KB Output is correct
13 Correct 33 ms 50588 KB Output is correct
14 Correct 37 ms 50748 KB Output is correct
15 Correct 36 ms 50740 KB Output is correct
16 Correct 33 ms 50692 KB Output is correct
17 Correct 31 ms 49972 KB Output is correct
18 Correct 32 ms 50632 KB Output is correct
19 Correct 1132 ms 229324 KB Output is correct
20 Correct 1079 ms 229036 KB Output is correct
21 Correct 820 ms 228788 KB Output is correct
22 Correct 837 ms 228972 KB Output is correct
23 Correct 837 ms 228972 KB Output is correct
24 Correct 724 ms 228916 KB Output is correct
25 Correct 726 ms 228900 KB Output is correct
26 Correct 885 ms 229104 KB Output is correct
27 Correct 912 ms 228932 KB Output is correct
28 Correct 939 ms 228848 KB Output is correct
29 Correct 977 ms 228856 KB Output is correct
30 Correct 1018 ms 228960 KB Output is correct
31 Correct 1040 ms 228900 KB Output is correct
32 Correct 1032 ms 228796 KB Output is correct
33 Correct 992 ms 229004 KB Output is correct
34 Correct 660 ms 228776 KB Output is correct
35 Correct 700 ms 228880 KB Output is correct
36 Correct 664 ms 229060 KB Output is correct
37 Correct 651 ms 228892 KB Output is correct
38 Correct 662 ms 228804 KB Output is correct
39 Correct 853 ms 228808 KB Output is correct
40 Correct 567 ms 161824 KB Output is correct
41 Correct 949 ms 228792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47284 KB Output is correct
2 Correct 30 ms 47236 KB Output is correct
3 Correct 25 ms 47312 KB Output is correct
4 Correct 23 ms 47324 KB Output is correct
5 Correct 24 ms 47292 KB Output is correct
6 Correct 24 ms 47476 KB Output is correct
7 Correct 25 ms 47532 KB Output is correct
8 Correct 24 ms 47612 KB Output is correct
9 Correct 25 ms 47424 KB Output is correct
10 Correct 25 ms 47436 KB Output is correct
11 Correct 29 ms 48068 KB Output is correct
12 Correct 35 ms 50496 KB Output is correct
13 Correct 33 ms 50588 KB Output is correct
14 Correct 37 ms 50748 KB Output is correct
15 Correct 36 ms 50740 KB Output is correct
16 Correct 33 ms 50692 KB Output is correct
17 Correct 31 ms 49972 KB Output is correct
18 Correct 32 ms 50632 KB Output is correct
19 Runtime error 206 ms 157456 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -