Submission #936946

# Submission time Handle Problem Language Result Execution time Memory
936946 2024-03-03T05:45:27 Z VinhLuu Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
854 ms 124420 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 '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 8 ms 26972 KB Output is correct
2 Correct 6 ms 27120 KB Output is correct
3 Correct 6 ms 26968 KB Output is correct
4 Correct 6 ms 27136 KB Output is correct
5 Correct 6 ms 26972 KB Output is correct
6 Correct 6 ms 27096 KB Output is correct
7 Correct 6 ms 26972 KB Output is correct
8 Correct 7 ms 26972 KB Output is correct
9 Correct 6 ms 26968 KB Output is correct
10 Correct 6 ms 26972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 26972 KB Output is correct
2 Correct 6 ms 27120 KB Output is correct
3 Correct 6 ms 26968 KB Output is correct
4 Correct 6 ms 27136 KB Output is correct
5 Correct 6 ms 26972 KB Output is correct
6 Correct 6 ms 27096 KB Output is correct
7 Correct 6 ms 26972 KB Output is correct
8 Correct 7 ms 26972 KB Output is correct
9 Correct 6 ms 26968 KB Output is correct
10 Correct 6 ms 26972 KB Output is correct
11 Correct 7 ms 27228 KB Output is correct
12 Correct 8 ms 27224 KB Output is correct
13 Correct 7 ms 27224 KB Output is correct
14 Correct 9 ms 29532 KB Output is correct
15 Correct 9 ms 29392 KB Output is correct
16 Correct 9 ms 29532 KB Output is correct
17 Correct 9 ms 29444 KB Output is correct
18 Correct 8 ms 29272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 854 ms 121460 KB Output is correct
2 Correct 833 ms 122452 KB Output is correct
3 Correct 848 ms 122296 KB Output is correct
4 Correct 828 ms 122552 KB Output is correct
5 Correct 785 ms 123108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 38736 KB Output is correct
2 Correct 54 ms 38948 KB Output is correct
3 Correct 53 ms 38736 KB Output is correct
4 Correct 54 ms 38888 KB Output is correct
5 Correct 56 ms 38840 KB Output is correct
6 Correct 44 ms 38636 KB Output is correct
7 Correct 44 ms 38768 KB Output is correct
8 Correct 51 ms 38148 KB Output is correct
9 Correct 31 ms 33536 KB Output is correct
10 Correct 53 ms 38160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 26972 KB Output is correct
2 Correct 6 ms 27120 KB Output is correct
3 Correct 6 ms 26968 KB Output is correct
4 Correct 6 ms 27136 KB Output is correct
5 Correct 6 ms 26972 KB Output is correct
6 Correct 6 ms 27096 KB Output is correct
7 Correct 6 ms 26972 KB Output is correct
8 Correct 7 ms 26972 KB Output is correct
9 Correct 6 ms 26968 KB Output is correct
10 Correct 6 ms 26972 KB Output is correct
11 Correct 7 ms 27228 KB Output is correct
12 Correct 8 ms 27224 KB Output is correct
13 Correct 7 ms 27224 KB Output is correct
14 Correct 9 ms 29532 KB Output is correct
15 Correct 9 ms 29392 KB Output is correct
16 Correct 9 ms 29532 KB Output is correct
17 Correct 9 ms 29444 KB Output is correct
18 Correct 8 ms 29272 KB Output is correct
19 Correct 144 ms 48976 KB Output is correct
20 Correct 132 ms 48992 KB Output is correct
21 Correct 112 ms 49348 KB Output is correct
22 Correct 115 ms 49252 KB Output is correct
23 Correct 114 ms 49232 KB Output is correct
24 Correct 103 ms 49232 KB Output is correct
25 Correct 99 ms 49240 KB Output is correct
26 Correct 113 ms 49232 KB Output is correct
27 Correct 122 ms 49236 KB Output is correct
28 Correct 117 ms 49140 KB Output is correct
29 Correct 120 ms 48884 KB Output is correct
30 Correct 118 ms 48976 KB Output is correct
31 Correct 119 ms 48980 KB Output is correct
32 Correct 117 ms 49020 KB Output is correct
33 Correct 118 ms 48980 KB Output is correct
34 Correct 93 ms 48720 KB Output is correct
35 Correct 88 ms 48564 KB Output is correct
36 Correct 93 ms 48464 KB Output is correct
37 Correct 88 ms 48464 KB Output is correct
38 Correct 90 ms 48708 KB Output is correct
39 Correct 116 ms 47108 KB Output is correct
40 Correct 88 ms 43772 KB Output is correct
41 Correct 106 ms 46424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 26972 KB Output is correct
2 Correct 6 ms 27120 KB Output is correct
3 Correct 6 ms 26968 KB Output is correct
4 Correct 6 ms 27136 KB Output is correct
5 Correct 6 ms 26972 KB Output is correct
6 Correct 6 ms 27096 KB Output is correct
7 Correct 6 ms 26972 KB Output is correct
8 Correct 7 ms 26972 KB Output is correct
9 Correct 6 ms 26968 KB Output is correct
10 Correct 6 ms 26972 KB Output is correct
11 Correct 7 ms 27228 KB Output is correct
12 Correct 8 ms 27224 KB Output is correct
13 Correct 7 ms 27224 KB Output is correct
14 Correct 9 ms 29532 KB Output is correct
15 Correct 9 ms 29392 KB Output is correct
16 Correct 9 ms 29532 KB Output is correct
17 Correct 9 ms 29444 KB Output is correct
18 Correct 8 ms 29272 KB Output is correct
19 Correct 854 ms 121460 KB Output is correct
20 Correct 833 ms 122452 KB Output is correct
21 Correct 848 ms 122296 KB Output is correct
22 Correct 828 ms 122552 KB Output is correct
23 Correct 785 ms 123108 KB Output is correct
24 Correct 58 ms 38736 KB Output is correct
25 Correct 54 ms 38948 KB Output is correct
26 Correct 53 ms 38736 KB Output is correct
27 Correct 54 ms 38888 KB Output is correct
28 Correct 56 ms 38840 KB Output is correct
29 Correct 44 ms 38636 KB Output is correct
30 Correct 44 ms 38768 KB Output is correct
31 Correct 51 ms 38148 KB Output is correct
32 Correct 31 ms 33536 KB Output is correct
33 Correct 53 ms 38160 KB Output is correct
34 Correct 144 ms 48976 KB Output is correct
35 Correct 132 ms 48992 KB Output is correct
36 Correct 112 ms 49348 KB Output is correct
37 Correct 115 ms 49252 KB Output is correct
38 Correct 114 ms 49232 KB Output is correct
39 Correct 103 ms 49232 KB Output is correct
40 Correct 99 ms 49240 KB Output is correct
41 Correct 113 ms 49232 KB Output is correct
42 Correct 122 ms 49236 KB Output is correct
43 Correct 117 ms 49140 KB Output is correct
44 Correct 120 ms 48884 KB Output is correct
45 Correct 118 ms 48976 KB Output is correct
46 Correct 119 ms 48980 KB Output is correct
47 Correct 117 ms 49020 KB Output is correct
48 Correct 118 ms 48980 KB Output is correct
49 Correct 93 ms 48720 KB Output is correct
50 Correct 88 ms 48564 KB Output is correct
51 Correct 93 ms 48464 KB Output is correct
52 Correct 88 ms 48464 KB Output is correct
53 Correct 90 ms 48708 KB Output is correct
54 Correct 116 ms 47108 KB Output is correct
55 Correct 88 ms 43772 KB Output is correct
56 Correct 106 ms 46424 KB Output is correct
57 Correct 830 ms 123544 KB Output is correct
58 Correct 806 ms 123376 KB Output is correct
59 Correct 761 ms 124016 KB Output is correct
60 Correct 755 ms 124244 KB Output is correct
61 Correct 765 ms 124016 KB Output is correct
62 Correct 751 ms 124244 KB Output is correct
63 Correct 482 ms 123928 KB Output is correct
64 Correct 481 ms 124240 KB Output is correct
65 Correct 752 ms 124420 KB Output is correct
66 Correct 747 ms 124404 KB Output is correct
67 Correct 710 ms 124276 KB Output is correct
68 Correct 777 ms 123484 KB Output is correct
69 Correct 784 ms 123732 KB Output is correct
70 Correct 765 ms 123732 KB Output is correct
71 Correct 767 ms 123520 KB Output is correct
72 Correct 774 ms 123404 KB Output is correct
73 Correct 414 ms 118084 KB Output is correct
74 Correct 422 ms 119280 KB Output is correct
75 Correct 415 ms 118100 KB Output is correct
76 Correct 410 ms 118376 KB Output is correct
77 Correct 425 ms 118088 KB Output is correct
78 Correct 686 ms 114928 KB Output is correct
79 Correct 523 ms 98140 KB Output is correct
80 Correct 693 ms 112676 KB Output is correct