Submission #936947

# Submission time Handle Problem Language Result Execution time Memory
936947 2024-03-03T05:46:17 Z VinhLuu Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++11
100 / 100
887 ms 116140 KB
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(lmao) lmao.begin(), lmao.end()

using namespace std;

typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 1e6 + 5;
const int oo = 1e16;
const int mod = 1e9 + 7;

int n, m, a[N], kq[N];
vector<array<int, 3>> vr[N];

namespace AC{
    int st[N << 1];
    void update(int i,int x){
        i += n - 1;
        st[i] = max(st[i], x);
        while(i > 1){
            i /= 2;
            st[i] = max(st[i << 1], st[i << 1|1]);
        }
    }

    int get(int l,int r){
        r++;
        int ret = -oo;
        for(l += n - 1, r += n - 1; l < r; l /= 2, r /= 2){
            if(l & 1) ret = max(ret, st[l ++]);
            if(r & 1) ret = max(ret, st[-- r]);
        }
        return ret;
    }

    void solve(){
        stack<int> s;
        for(int i = 1; i <= n * 2; i ++) st[i] = -oo;
        for(int i = 1; i <= n; i ++){
            while(!s.empty() && a[s.top()] <= a[i]) s.pop();
            if(!s.empty()) update(s.top(), a[i] + a[s.top()]);
            for(auto [id, l, k] : vr[i]) kq[id] = (get(l, i) <= k);
            s.push(i);
        }
        for(int i = 1; i <= m; i ++) cout << kq[i] << "\n";
    }
}

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

    #define task "v"
    if(fopen(task ".inp","r")){
        freopen(task ".inp","r",stdin);
        freopen(task ".out","w",stdout);
    }

    cin >> n >> m;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    for(int i = 1; i <= m; i ++){
        int l, r, k; cin >> l >> r >> k;
        vr[r].pb({i, l, k});
    }
    AC :: solve();
}

Compilation message

sortbooks.cpp: In function 'void AC::solve()':
sortbooks.cpp:51:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |             for(auto [id, l, k] : vr[i]) kq[id] = (get(l, i) <= k);
      |                      ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 26968 KB Output is correct
2 Correct 6 ms 26968 KB Output is correct
3 Correct 6 ms 26968 KB Output is correct
4 Correct 6 ms 26972 KB Output is correct
5 Correct 6 ms 27136 KB Output is correct
6 Correct 7 ms 26972 KB Output is correct
7 Correct 6 ms 27184 KB Output is correct
8 Correct 8 ms 26968 KB Output is correct
9 Correct 6 ms 27164 KB Output is correct
10 Correct 7 ms 26968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 26968 KB Output is correct
2 Correct 6 ms 26968 KB Output is correct
3 Correct 6 ms 26968 KB Output is correct
4 Correct 6 ms 26972 KB Output is correct
5 Correct 6 ms 27136 KB Output is correct
6 Correct 7 ms 26972 KB Output is correct
7 Correct 6 ms 27184 KB Output is correct
8 Correct 8 ms 26968 KB Output is correct
9 Correct 6 ms 27164 KB Output is correct
10 Correct 7 ms 26968 KB Output is correct
11 Correct 8 ms 27228 KB Output is correct
12 Correct 8 ms 27228 KB Output is correct
13 Correct 9 ms 27252 KB Output is correct
14 Correct 10 ms 29532 KB Output is correct
15 Correct 11 ms 29532 KB Output is correct
16 Correct 9 ms 29372 KB Output is correct
17 Correct 9 ms 29372 KB Output is correct
18 Correct 9 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 880 ms 114004 KB Output is correct
2 Correct 856 ms 115000 KB Output is correct
3 Correct 887 ms 114328 KB Output is correct
4 Correct 862 ms 114840 KB Output is correct
5 Correct 788 ms 114788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 38480 KB Output is correct
2 Correct 58 ms 38740 KB Output is correct
3 Correct 56 ms 38752 KB Output is correct
4 Correct 55 ms 38484 KB Output is correct
5 Correct 55 ms 38732 KB Output is correct
6 Correct 44 ms 38736 KB Output is correct
7 Correct 44 ms 38740 KB Output is correct
8 Correct 53 ms 38112 KB Output is correct
9 Correct 33 ms 33544 KB Output is correct
10 Correct 51 ms 37904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 26968 KB Output is correct
2 Correct 6 ms 26968 KB Output is correct
3 Correct 6 ms 26968 KB Output is correct
4 Correct 6 ms 26972 KB Output is correct
5 Correct 6 ms 27136 KB Output is correct
6 Correct 7 ms 26972 KB Output is correct
7 Correct 6 ms 27184 KB Output is correct
8 Correct 8 ms 26968 KB Output is correct
9 Correct 6 ms 27164 KB Output is correct
10 Correct 7 ms 26968 KB Output is correct
11 Correct 8 ms 27228 KB Output is correct
12 Correct 8 ms 27228 KB Output is correct
13 Correct 9 ms 27252 KB Output is correct
14 Correct 10 ms 29532 KB Output is correct
15 Correct 11 ms 29532 KB Output is correct
16 Correct 9 ms 29372 KB Output is correct
17 Correct 9 ms 29372 KB Output is correct
18 Correct 9 ms 29276 KB Output is correct
19 Correct 137 ms 47668 KB Output is correct
20 Correct 136 ms 47700 KB Output is correct
21 Correct 117 ms 48364 KB Output is correct
22 Correct 117 ms 48212 KB Output is correct
23 Correct 116 ms 48208 KB Output is correct
24 Correct 103 ms 48232 KB Output is correct
25 Correct 102 ms 48056 KB Output is correct
26 Correct 117 ms 47924 KB Output is correct
27 Correct 119 ms 48072 KB Output is correct
28 Correct 118 ms 47852 KB Output is correct
29 Correct 120 ms 47640 KB Output is correct
30 Correct 122 ms 47700 KB Output is correct
31 Correct 124 ms 47720 KB Output is correct
32 Correct 124 ms 47696 KB Output is correct
33 Correct 129 ms 47760 KB Output is correct
34 Correct 94 ms 47660 KB Output is correct
35 Correct 93 ms 47640 KB Output is correct
36 Correct 104 ms 47260 KB Output is correct
37 Correct 92 ms 47188 KB Output is correct
38 Correct 92 ms 47440 KB Output is correct
39 Correct 117 ms 46084 KB Output is correct
40 Correct 91 ms 43856 KB Output is correct
41 Correct 119 ms 47072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 26968 KB Output is correct
2 Correct 6 ms 26968 KB Output is correct
3 Correct 6 ms 26968 KB Output is correct
4 Correct 6 ms 26972 KB Output is correct
5 Correct 6 ms 27136 KB Output is correct
6 Correct 7 ms 26972 KB Output is correct
7 Correct 6 ms 27184 KB Output is correct
8 Correct 8 ms 26968 KB Output is correct
9 Correct 6 ms 27164 KB Output is correct
10 Correct 7 ms 26968 KB Output is correct
11 Correct 8 ms 27228 KB Output is correct
12 Correct 8 ms 27228 KB Output is correct
13 Correct 9 ms 27252 KB Output is correct
14 Correct 10 ms 29532 KB Output is correct
15 Correct 11 ms 29532 KB Output is correct
16 Correct 9 ms 29372 KB Output is correct
17 Correct 9 ms 29372 KB Output is correct
18 Correct 9 ms 29276 KB Output is correct
19 Correct 880 ms 114004 KB Output is correct
20 Correct 856 ms 115000 KB Output is correct
21 Correct 887 ms 114328 KB Output is correct
22 Correct 862 ms 114840 KB Output is correct
23 Correct 788 ms 114788 KB Output is correct
24 Correct 64 ms 38480 KB Output is correct
25 Correct 58 ms 38740 KB Output is correct
26 Correct 56 ms 38752 KB Output is correct
27 Correct 55 ms 38484 KB Output is correct
28 Correct 55 ms 38732 KB Output is correct
29 Correct 44 ms 38736 KB Output is correct
30 Correct 44 ms 38740 KB Output is correct
31 Correct 53 ms 38112 KB Output is correct
32 Correct 33 ms 33544 KB Output is correct
33 Correct 51 ms 37904 KB Output is correct
34 Correct 137 ms 47668 KB Output is correct
35 Correct 136 ms 47700 KB Output is correct
36 Correct 117 ms 48364 KB Output is correct
37 Correct 117 ms 48212 KB Output is correct
38 Correct 116 ms 48208 KB Output is correct
39 Correct 103 ms 48232 KB Output is correct
40 Correct 102 ms 48056 KB Output is correct
41 Correct 117 ms 47924 KB Output is correct
42 Correct 119 ms 48072 KB Output is correct
43 Correct 118 ms 47852 KB Output is correct
44 Correct 120 ms 47640 KB Output is correct
45 Correct 122 ms 47700 KB Output is correct
46 Correct 124 ms 47720 KB Output is correct
47 Correct 124 ms 47696 KB Output is correct
48 Correct 129 ms 47760 KB Output is correct
49 Correct 94 ms 47660 KB Output is correct
50 Correct 93 ms 47640 KB Output is correct
51 Correct 104 ms 47260 KB Output is correct
52 Correct 92 ms 47188 KB Output is correct
53 Correct 92 ms 47440 KB Output is correct
54 Correct 117 ms 46084 KB Output is correct
55 Correct 91 ms 43856 KB Output is correct
56 Correct 119 ms 47072 KB Output is correct
57 Correct 877 ms 115280 KB Output is correct
58 Correct 826 ms 115180 KB Output is correct
59 Correct 771 ms 116068 KB Output is correct
60 Correct 770 ms 115892 KB Output is correct
61 Correct 770 ms 116052 KB Output is correct
62 Correct 773 ms 116052 KB Output is correct
63 Correct 479 ms 108656 KB Output is correct
64 Correct 488 ms 108652 KB Output is correct
65 Correct 751 ms 116028 KB Output is correct
66 Correct 730 ms 116032 KB Output is correct
67 Correct 722 ms 116140 KB Output is correct
68 Correct 782 ms 115052 KB Output is correct
69 Correct 826 ms 115120 KB Output is correct
70 Correct 791 ms 115284 KB Output is correct
71 Correct 788 ms 115284 KB Output is correct
72 Correct 793 ms 115540 KB Output is correct
73 Correct 438 ms 110928 KB Output is correct
74 Correct 430 ms 111760 KB Output is correct
75 Correct 425 ms 111036 KB Output is correct
76 Correct 427 ms 111284 KB Output is correct
77 Correct 435 ms 110996 KB Output is correct
78 Correct 670 ms 108208 KB Output is correct
79 Correct 518 ms 87636 KB Output is correct
80 Correct 670 ms 99848 KB Output is correct