Submission #1040425

# Submission time Handle Problem Language Result Execution time Memory
1040425 2024-08-01T03:54:09 Z Neco_arc Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
604 ms 39888 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 8540 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 8540 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 8664 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 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 8540 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 8664 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 8672 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 3 ms 8540 KB Output is correct
16 Correct 3 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 522 ms 39764 KB Output is correct
2 Correct 540 ms 39760 KB Output is correct
3 Correct 526 ms 39764 KB Output is correct
4 Correct 519 ms 39764 KB Output is correct
5 Correct 543 ms 33616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 9808 KB Output is correct
2 Correct 42 ms 9812 KB Output is correct
3 Correct 44 ms 8832 KB Output is correct
4 Correct 43 ms 8788 KB Output is correct
5 Correct 45 ms 8708 KB Output is correct
6 Correct 37 ms 8788 KB Output is correct
7 Correct 37 ms 8784 KB Output is correct
8 Correct 36 ms 8788 KB Output is correct
9 Correct 21 ms 8792 KB Output is correct
10 Correct 36 ms 8776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 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 8540 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 8664 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 8672 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 3 ms 8540 KB Output is correct
16 Correct 3 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 13060 KB Output is correct
20 Correct 97 ms 13140 KB Output is correct
21 Correct 90 ms 13140 KB Output is correct
22 Correct 92 ms 13140 KB Output is correct
23 Correct 94 ms 13144 KB Output is correct
24 Correct 93 ms 11092 KB Output is correct
25 Correct 94 ms 11092 KB Output is correct
26 Correct 100 ms 11092 KB Output is correct
27 Correct 97 ms 11008 KB Output is correct
28 Correct 95 ms 11088 KB Output is correct
29 Correct 114 ms 11092 KB Output is correct
30 Correct 121 ms 11088 KB Output is correct
31 Correct 98 ms 11012 KB Output is correct
32 Correct 100 ms 11004 KB Output is correct
33 Correct 100 ms 10952 KB Output is correct
34 Correct 87 ms 11092 KB Output is correct
35 Correct 91 ms 11096 KB Output is correct
36 Correct 86 ms 11088 KB Output is correct
37 Correct 85 ms 11088 KB Output is correct
38 Correct 87 ms 11092 KB Output is correct
39 Correct 96 ms 11856 KB Output is correct
40 Correct 84 ms 10976 KB Output is correct
41 Correct 85 ms 10956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 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 8540 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 8664 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 8672 KB Output is correct
14 Correct 3 ms 8540 KB Output is correct
15 Correct 3 ms 8540 KB Output is correct
16 Correct 3 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 522 ms 39764 KB Output is correct
20 Correct 540 ms 39760 KB Output is correct
21 Correct 526 ms 39764 KB Output is correct
22 Correct 519 ms 39764 KB Output is correct
23 Correct 543 ms 33616 KB Output is correct
24 Correct 44 ms 9808 KB Output is correct
25 Correct 42 ms 9812 KB Output is correct
26 Correct 44 ms 8832 KB Output is correct
27 Correct 43 ms 8788 KB Output is correct
28 Correct 45 ms 8708 KB Output is correct
29 Correct 37 ms 8788 KB Output is correct
30 Correct 37 ms 8784 KB Output is correct
31 Correct 36 ms 8788 KB Output is correct
32 Correct 21 ms 8792 KB Output is correct
33 Correct 36 ms 8776 KB Output is correct
34 Correct 101 ms 13060 KB Output is correct
35 Correct 97 ms 13140 KB Output is correct
36 Correct 90 ms 13140 KB Output is correct
37 Correct 92 ms 13140 KB Output is correct
38 Correct 94 ms 13144 KB Output is correct
39 Correct 93 ms 11092 KB Output is correct
40 Correct 94 ms 11092 KB Output is correct
41 Correct 100 ms 11092 KB Output is correct
42 Correct 97 ms 11008 KB Output is correct
43 Correct 95 ms 11088 KB Output is correct
44 Correct 114 ms 11092 KB Output is correct
45 Correct 121 ms 11088 KB Output is correct
46 Correct 98 ms 11012 KB Output is correct
47 Correct 100 ms 11004 KB Output is correct
48 Correct 100 ms 10952 KB Output is correct
49 Correct 87 ms 11092 KB Output is correct
50 Correct 91 ms 11096 KB Output is correct
51 Correct 86 ms 11088 KB Output is correct
52 Correct 85 ms 11088 KB Output is correct
53 Correct 87 ms 11092 KB Output is correct
54 Correct 96 ms 11856 KB Output is correct
55 Correct 84 ms 10976 KB Output is correct
56 Correct 85 ms 10956 KB Output is correct
57 Correct 559 ms 39872 KB Output is correct
58 Correct 542 ms 39888 KB Output is correct
59 Correct 569 ms 39888 KB Output is correct
60 Correct 523 ms 39764 KB Output is correct
61 Correct 551 ms 39760 KB Output is correct
62 Correct 524 ms 39760 KB Output is correct
63 Correct 487 ms 33588 KB Output is correct
64 Correct 521 ms 33672 KB Output is correct
65 Correct 573 ms 33752 KB Output is correct
66 Correct 604 ms 33744 KB Output is correct
67 Correct 539 ms 33592 KB Output is correct
68 Correct 561 ms 33736 KB Output is correct
69 Correct 547 ms 33596 KB Output is correct
70 Correct 554 ms 33752 KB Output is correct
71 Correct 555 ms 33744 KB Output is correct
72 Correct 546 ms 33764 KB Output is correct
73 Correct 468 ms 33744 KB Output is correct
74 Correct 495 ms 33876 KB Output is correct
75 Correct 464 ms 33992 KB Output is correct
76 Correct 464 ms 33636 KB Output is correct
77 Correct 528 ms 33700 KB Output is correct
78 Correct 483 ms 35900 KB Output is correct
79 Correct 375 ms 33736 KB Output is correct
80 Correct 430 ms 33740 KB Output is correct