Submission #978891

# Submission time Handle Problem Language Result Execution time Memory
978891 2024-05-10T00:47:15 Z Sofiatpc Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1516 ms 117196 KB
#include <bits/stdc++.h>

using namespace std;

struct query{
    int r,k,id;
};
#define sz(v) (int)v.size()
const int MAXN = 1e6+5;
int w[MAXN], r[MAXN], ans[MAXN], mx[MAXN*4], mxs[MAXN*4];
vector<int> st;
vector<query> q[MAXN];
query temp; 

void build(int node, int l, int r){
    mxs[node] = -1;
    if(l==r){
        mx[node] = w[l];
        return;
    }

    int mid = (l+r)>>1, e = node*2, d = node*2+1;
    build(e,l,mid); build(d,mid+1,r);
    mx[node] = max(mx[e],mx[d]);
}

int query(int node, int l, int r, int i, int j){
    if(j < l || r < i)return -1;
    if(i <= l && r <= j)return mx[node];
    int mid = (l+r)>>1, e = node*2, d = node*2+1;
    return max(query(e,l,mid,i,j),query(d,mid+1,r,i,j));
}

void updateS(int node, int l, int r, int i, int x){
    if(i < l || r < i)return;
    if(l==r){
        mxs[node] = x;
        return;
    }

    int mid = (l+r)>>1, e = node*2, d = node*2+1;
    updateS(e,l,mid,i,x); updateS(d,mid+1,r,i,x);
    mxs[node] = max(mxs[e],mxs[d]);
}

int queryS(int node, int l, int r, int i, int j){
    if(j < l || r < i)return -1;
    if(i <= l && r <= j)return mxs[node];
    int mid = (l+r)>>1, e = node*2, d = node*2+1;
    return max(queryS(e,l,mid,i,j),queryS(d,mid+1,r,i,j));
}

int bb( int x){
    int l = 0, r = sz(st)-1;
    while(l!=r){
        int mid = (l+r)/2;
        if(st[mid] <= x)r = mid;
        else l = mid+1;
    }
    return st[l];
}

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

    int n,m; cin>>n>>m;
    for(int i = 1; i <= n; i++)cin>>w[i];
    build(1,1,n);

    for(int i = 1; i <= m; i++){
        int l;
        cin>>l>>temp.r>>temp.k;
        temp.id = i;
        q[l].push_back(temp);
    }

    for(int i = n; i >= 1; i--){
        int mx = -1;
        while(sz(st) > 0 && w[st.back()] < w[i]){
            updateS(1,1,n,st.back(),0);
            mx = w[st.back()];
            st.pop_back();
        }
        if(mx >= 0)updateS(1,1,n,i,w[i]+mx);
        st.push_back(i);

        for(int j = 0; j < sz(q[i]); j++){
            //for(int z : st)cout<<z<<" "<<w[z]<<", "; cout<<"\n";
            int u = bb(q[i][j].r); 
            int a = queryS(1,1,n,i,u-1), b = query(1,1,n,u+1,q[i][j].r);
            //cout<<u<<" "<<a<<" "<<b<<"\n";
            if(b >= 0)b += w[u];

            ans[q[i][j].id] = ( max(a,b) <= q[i][j].k );
        }
    }

    for(int i = 1; i <= m; i++)cout<<ans[i]<<"\n";
    
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31324 KB Output is correct
2 Correct 8 ms 31324 KB Output is correct
3 Correct 7 ms 31340 KB Output is correct
4 Correct 8 ms 31500 KB Output is correct
5 Correct 7 ms 31428 KB Output is correct
6 Correct 7 ms 31420 KB Output is correct
7 Correct 7 ms 31444 KB Output is correct
8 Correct 7 ms 31420 KB Output is correct
9 Correct 7 ms 31320 KB Output is correct
10 Correct 7 ms 31324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31324 KB Output is correct
2 Correct 8 ms 31324 KB Output is correct
3 Correct 7 ms 31340 KB Output is correct
4 Correct 8 ms 31500 KB Output is correct
5 Correct 7 ms 31428 KB Output is correct
6 Correct 7 ms 31420 KB Output is correct
7 Correct 7 ms 31444 KB Output is correct
8 Correct 7 ms 31420 KB Output is correct
9 Correct 7 ms 31320 KB Output is correct
10 Correct 7 ms 31324 KB Output is correct
11 Correct 9 ms 31324 KB Output is correct
12 Correct 10 ms 33556 KB Output is correct
13 Correct 10 ms 33628 KB Output is correct
14 Correct 11 ms 33624 KB Output is correct
15 Correct 11 ms 33656 KB Output is correct
16 Correct 10 ms 33716 KB Output is correct
17 Correct 9 ms 33628 KB Output is correct
18 Correct 10 ms 33680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1453 ms 94388 KB Output is correct
2 Correct 1516 ms 95036 KB Output is correct
3 Correct 1449 ms 94832 KB Output is correct
4 Correct 1465 ms 94856 KB Output is correct
5 Correct 1359 ms 99036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 36972 KB Output is correct
2 Correct 104 ms 37456 KB Output is correct
3 Correct 92 ms 38100 KB Output is correct
4 Correct 98 ms 38340 KB Output is correct
5 Correct 95 ms 38344 KB Output is correct
6 Correct 76 ms 37588 KB Output is correct
7 Correct 74 ms 37588 KB Output is correct
8 Correct 86 ms 37384 KB Output is correct
9 Correct 49 ms 34308 KB Output is correct
10 Correct 88 ms 37432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31324 KB Output is correct
2 Correct 8 ms 31324 KB Output is correct
3 Correct 7 ms 31340 KB Output is correct
4 Correct 8 ms 31500 KB Output is correct
5 Correct 7 ms 31428 KB Output is correct
6 Correct 7 ms 31420 KB Output is correct
7 Correct 7 ms 31444 KB Output is correct
8 Correct 7 ms 31420 KB Output is correct
9 Correct 7 ms 31320 KB Output is correct
10 Correct 7 ms 31324 KB Output is correct
11 Correct 9 ms 31324 KB Output is correct
12 Correct 10 ms 33556 KB Output is correct
13 Correct 10 ms 33628 KB Output is correct
14 Correct 11 ms 33624 KB Output is correct
15 Correct 11 ms 33656 KB Output is correct
16 Correct 10 ms 33716 KB Output is correct
17 Correct 9 ms 33628 KB Output is correct
18 Correct 10 ms 33680 KB Output is correct
19 Correct 247 ms 46864 KB Output is correct
20 Correct 269 ms 46884 KB Output is correct
21 Correct 223 ms 46168 KB Output is correct
22 Correct 209 ms 46164 KB Output is correct
23 Correct 227 ms 46180 KB Output is correct
24 Correct 171 ms 46912 KB Output is correct
25 Correct 169 ms 46988 KB Output is correct
26 Correct 193 ms 47284 KB Output is correct
27 Correct 193 ms 47224 KB Output is correct
28 Correct 196 ms 47308 KB Output is correct
29 Correct 208 ms 47816 KB Output is correct
30 Correct 218 ms 48076 KB Output is correct
31 Correct 215 ms 47812 KB Output is correct
32 Correct 202 ms 47812 KB Output is correct
33 Correct 226 ms 47928 KB Output is correct
34 Correct 155 ms 46336 KB Output is correct
35 Correct 153 ms 46272 KB Output is correct
36 Correct 153 ms 46052 KB Output is correct
37 Correct 155 ms 46020 KB Output is correct
38 Correct 154 ms 46280 KB Output is correct
39 Correct 186 ms 45684 KB Output is correct
40 Correct 144 ms 42596 KB Output is correct
41 Correct 179 ms 45060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 31324 KB Output is correct
2 Correct 8 ms 31324 KB Output is correct
3 Correct 7 ms 31340 KB Output is correct
4 Correct 8 ms 31500 KB Output is correct
5 Correct 7 ms 31428 KB Output is correct
6 Correct 7 ms 31420 KB Output is correct
7 Correct 7 ms 31444 KB Output is correct
8 Correct 7 ms 31420 KB Output is correct
9 Correct 7 ms 31320 KB Output is correct
10 Correct 7 ms 31324 KB Output is correct
11 Correct 9 ms 31324 KB Output is correct
12 Correct 10 ms 33556 KB Output is correct
13 Correct 10 ms 33628 KB Output is correct
14 Correct 11 ms 33624 KB Output is correct
15 Correct 11 ms 33656 KB Output is correct
16 Correct 10 ms 33716 KB Output is correct
17 Correct 9 ms 33628 KB Output is correct
18 Correct 10 ms 33680 KB Output is correct
19 Correct 1453 ms 94388 KB Output is correct
20 Correct 1516 ms 95036 KB Output is correct
21 Correct 1449 ms 94832 KB Output is correct
22 Correct 1465 ms 94856 KB Output is correct
23 Correct 1359 ms 99036 KB Output is correct
24 Correct 113 ms 36972 KB Output is correct
25 Correct 104 ms 37456 KB Output is correct
26 Correct 92 ms 38100 KB Output is correct
27 Correct 98 ms 38340 KB Output is correct
28 Correct 95 ms 38344 KB Output is correct
29 Correct 76 ms 37588 KB Output is correct
30 Correct 74 ms 37588 KB Output is correct
31 Correct 86 ms 37384 KB Output is correct
32 Correct 49 ms 34308 KB Output is correct
33 Correct 88 ms 37432 KB Output is correct
34 Correct 247 ms 46864 KB Output is correct
35 Correct 269 ms 46884 KB Output is correct
36 Correct 223 ms 46168 KB Output is correct
37 Correct 209 ms 46164 KB Output is correct
38 Correct 227 ms 46180 KB Output is correct
39 Correct 171 ms 46912 KB Output is correct
40 Correct 169 ms 46988 KB Output is correct
41 Correct 193 ms 47284 KB Output is correct
42 Correct 193 ms 47224 KB Output is correct
43 Correct 196 ms 47308 KB Output is correct
44 Correct 208 ms 47816 KB Output is correct
45 Correct 218 ms 48076 KB Output is correct
46 Correct 215 ms 47812 KB Output is correct
47 Correct 202 ms 47812 KB Output is correct
48 Correct 226 ms 47928 KB Output is correct
49 Correct 155 ms 46336 KB Output is correct
50 Correct 153 ms 46272 KB Output is correct
51 Correct 153 ms 46052 KB Output is correct
52 Correct 155 ms 46020 KB Output is correct
53 Correct 154 ms 46280 KB Output is correct
54 Correct 186 ms 45684 KB Output is correct
55 Correct 144 ms 42596 KB Output is correct
56 Correct 179 ms 45060 KB Output is correct
57 Correct 1420 ms 112548 KB Output is correct
58 Correct 1459 ms 112748 KB Output is correct
59 Correct 1443 ms 110672 KB Output is correct
60 Correct 1402 ms 110676 KB Output is correct
61 Correct 1403 ms 110436 KB Output is correct
62 Correct 1422 ms 110428 KB Output is correct
63 Correct 892 ms 108812 KB Output is correct
64 Correct 875 ms 109080 KB Output is correct
65 Correct 1187 ms 114564 KB Output is correct
66 Correct 1210 ms 114720 KB Output is correct
67 Correct 1221 ms 114228 KB Output is correct
68 Correct 1335 ms 117020 KB Output is correct
69 Correct 1302 ms 117196 KB Output is correct
70 Correct 1310 ms 116160 KB Output is correct
71 Correct 1290 ms 116248 KB Output is correct
72 Correct 1343 ms 116572 KB Output is correct
73 Correct 785 ms 106784 KB Output is correct
74 Correct 803 ms 107524 KB Output is correct
75 Correct 782 ms 106452 KB Output is correct
76 Correct 804 ms 106324 KB Output is correct
77 Correct 785 ms 106616 KB Output is correct
78 Correct 1121 ms 107256 KB Output is correct
79 Correct 785 ms 90596 KB Output is correct
80 Correct 1074 ms 103824 KB Output is correct