Submission #1040426

# Submission time Handle Problem Language Result Execution time Memory
1040426 2024-08-01T03:54:20 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
579 ms 39896 KB
#include <bits/stdc++.h>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL

#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Hedgehog Daniyar and Algorithms"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 1e6 + 7

using namespace std;

const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r)(rng);
}

int n, q;
struct QUERY {
    int l, r, k, id;
    bool operator<(const QUERY &other) const {
        return r < other.r;
    }
} qr[maxn];
int a[maxn];

namespace TRAU {

    int calc(int l, int r) {
        int Max = -1e9, ans = 0;
        fi(i, l, r) {
            if(a[i] < Max) ans = max(ans, a[i] + Max);
            Max = max(Max, a[i]);
        }
        return ans;
    }

    void solve() {
        fi(i, 1, q) {
            int l = qr[i].l, r = qr[i].r, k = qr[i].k;
            cout << (calc(l, r) <= k) << '\n';
        }
    }
}

namespace Subtrask2 {

    int f[maxn], stk[maxn];
    int ans[maxn];

    struct IT {
        int st[4 * maxn];
        void update(int x, int val, int id = 1, int l = 0, int r = n) {
            if(l > x || r < x) return ;
            if(l == r) return st[id] = max(st[id], val), void();

            int mid = (l + r) >> 1;
            update(x, val, _left), update(x, val, _right);
            st[id] = max(st[id * 2], st[id * 2 + 1]);
        }

        int get(int u, int v, int id = 1, int l = 0, int r = n) {
            if(l > v || r < u) return 0;
            if(u <= l && r <= v) return st[id];

            int mid = (l + r) >> 1;
            return max(get(u, v, _left), get(u, v, _right));
        }

    } St;

    void prepare() {
        int top = 0;
        fi(i, 1, n) {
            while(top && a[i] >= a[stk[top]]) --top;
            f[i] = stk[top], stk[++top] = i;
        }
    }

    void solve() {
        prepare();
        sort(qr + 1, qr + 1 + q);

        int j = 1;
        fi(i, 1, q) {
            while(j <= qr[i].r) {
                St.update(f[j], a[f[j]] + a[j]);
                ++j;
            }
            ans[qr[i].id] = (St.get(qr[i].l, qr[i].r) <= qr[i].k);
        }

        fi(i, 1, q) cout << ans[i] << '\n';

    }

}

void solve()
{

    cin >> n >> q;
    fi(i, 1, n) cin >> a[i];
    fi(i, 1, q) cin >> qr[i].l >> qr[i].r >> qr[i].k, qr[i].id = i;

//    TRAU::solve(); cout << '\n';
    Subtrask2::solve();


}


int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen(Neco".inp", "r")) {
        freopen(Neco".inp", "r", stdin);
        freopen(Neco".out", "w", stdout);
    }


    int nTest = 1;
//    cin >> nTest;


    while(nTest--)
    {
        solve();
    }


    return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:131:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  131 |         freopen(Neco".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:132:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |         freopen(Neco".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8792 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8792 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 2 ms 8608 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 3 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 524 ms 39880 KB Output is correct
2 Correct 568 ms 39760 KB Output is correct
3 Correct 561 ms 39896 KB Output is correct
4 Correct 550 ms 39756 KB Output is correct
5 Correct 549 ms 33616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 9808 KB Output is correct
2 Correct 48 ms 9808 KB Output is correct
3 Correct 42 ms 8764 KB Output is correct
4 Correct 42 ms 8784 KB Output is correct
5 Correct 67 ms 8900 KB Output is correct
6 Correct 37 ms 8788 KB Output is correct
7 Correct 36 ms 8788 KB Output is correct
8 Correct 35 ms 8784 KB Output is correct
9 Correct 38 ms 8796 KB Output is correct
10 Correct 41 ms 8784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8792 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 2 ms 8608 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 3 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 101 ms 13140 KB Output is correct
20 Correct 104 ms 13012 KB Output is correct
21 Correct 93 ms 13136 KB Output is correct
22 Correct 129 ms 13012 KB Output is correct
23 Correct 113 ms 13136 KB Output is correct
24 Correct 96 ms 10964 KB Output is correct
25 Correct 93 ms 10964 KB Output is correct
26 Correct 99 ms 11088 KB Output is correct
27 Correct 99 ms 10964 KB Output is correct
28 Correct 96 ms 10964 KB Output is correct
29 Correct 132 ms 10960 KB Output is correct
30 Correct 102 ms 11008 KB Output is correct
31 Correct 99 ms 11092 KB Output is correct
32 Correct 99 ms 10960 KB Output is correct
33 Correct 98 ms 10952 KB Output is correct
34 Correct 98 ms 11088 KB Output is correct
35 Correct 95 ms 10964 KB Output is correct
36 Correct 86 ms 11032 KB Output is correct
37 Correct 87 ms 11088 KB Output is correct
38 Correct 86 ms 11088 KB Output is correct
39 Correct 93 ms 11856 KB Output is correct
40 Correct 77 ms 11088 KB Output is correct
41 Correct 79 ms 10968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8792 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8540 KB Output is correct
13 Correct 2 ms 8608 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 3 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 524 ms 39880 KB Output is correct
20 Correct 568 ms 39760 KB Output is correct
21 Correct 561 ms 39896 KB Output is correct
22 Correct 550 ms 39756 KB Output is correct
23 Correct 549 ms 33616 KB Output is correct
24 Correct 44 ms 9808 KB Output is correct
25 Correct 48 ms 9808 KB Output is correct
26 Correct 42 ms 8764 KB Output is correct
27 Correct 42 ms 8784 KB Output is correct
28 Correct 67 ms 8900 KB Output is correct
29 Correct 37 ms 8788 KB Output is correct
30 Correct 36 ms 8788 KB Output is correct
31 Correct 35 ms 8784 KB Output is correct
32 Correct 38 ms 8796 KB Output is correct
33 Correct 41 ms 8784 KB Output is correct
34 Correct 101 ms 13140 KB Output is correct
35 Correct 104 ms 13012 KB Output is correct
36 Correct 93 ms 13136 KB Output is correct
37 Correct 129 ms 13012 KB Output is correct
38 Correct 113 ms 13136 KB Output is correct
39 Correct 96 ms 10964 KB Output is correct
40 Correct 93 ms 10964 KB Output is correct
41 Correct 99 ms 11088 KB Output is correct
42 Correct 99 ms 10964 KB Output is correct
43 Correct 96 ms 10964 KB Output is correct
44 Correct 132 ms 10960 KB Output is correct
45 Correct 102 ms 11008 KB Output is correct
46 Correct 99 ms 11092 KB Output is correct
47 Correct 99 ms 10960 KB Output is correct
48 Correct 98 ms 10952 KB Output is correct
49 Correct 98 ms 11088 KB Output is correct
50 Correct 95 ms 10964 KB Output is correct
51 Correct 86 ms 11032 KB Output is correct
52 Correct 87 ms 11088 KB Output is correct
53 Correct 86 ms 11088 KB Output is correct
54 Correct 93 ms 11856 KB Output is correct
55 Correct 77 ms 11088 KB Output is correct
56 Correct 79 ms 10968 KB Output is correct
57 Correct 529 ms 39884 KB Output is correct
58 Correct 557 ms 39880 KB Output is correct
59 Correct 544 ms 39760 KB Output is correct
60 Correct 522 ms 39892 KB Output is correct
61 Correct 547 ms 39760 KB Output is correct
62 Correct 527 ms 39764 KB Output is correct
63 Correct 503 ms 33616 KB Output is correct
64 Correct 514 ms 33620 KB Output is correct
65 Correct 539 ms 33632 KB Output is correct
66 Correct 535 ms 33744 KB Output is correct
67 Correct 528 ms 33624 KB Output is correct
68 Correct 549 ms 33620 KB Output is correct
69 Correct 579 ms 33616 KB Output is correct
70 Correct 536 ms 33620 KB Output is correct
71 Correct 556 ms 33732 KB Output is correct
72 Correct 558 ms 33752 KB Output is correct
73 Correct 462 ms 33668 KB Output is correct
74 Correct 472 ms 33736 KB Output is correct
75 Correct 461 ms 33692 KB Output is correct
76 Correct 461 ms 33620 KB Output is correct
77 Correct 499 ms 33736 KB Output is correct
78 Correct 497 ms 35920 KB Output is correct
79 Correct 377 ms 33748 KB Output is correct
80 Correct 443 ms 33620 KB Output is correct