Submission #737620

# Submission time Handle Problem Language Result Execution time Memory
737620 2023-05-07T12:40:29 Z PenguinsAreCute Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1332 ms 150264 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef pair<int,int> ii;
#define REP(i, a, b) for(int i = a; i < b; i++)
struct query{int x, y, k, idx;};
bool comp(query a, query b) {return a.y<b.y;}
struct node{
    int s,e,m,v;
    node *l,*r;
    node(int _s, int _e) {
        s=_s;e=_e;m=(s+e)>>1;v=-1210201069;
        if(s!=e){
            l=new node(s,m);
            r=new node(m+1,e);
        }
    }
    void up(int x, int u) {
        if(s==e) {v=max(v,u);return;}
        if(x<=m) l->up(x,u);
        else r->up(x,u);
        v=max(l->v,r->v);
    }
    int qry(int x, int y) {
        if(s==x&&e==y) return v;
        if(y<=m) return l->qry(x,y);
        if(x>m) return r->qry(x,y);
        return max(l->qry(x,m),r->qry(m+1,y));
    }
}*root;
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int N, M; cin >> N >> M;
    root=new node(0,N-1);
    int W[N];REP(i,0,N)cin>>W[i];
    query q[M];
    REP(i,0,M){
        cin>>q[i].x>>q[i].y>>q[i].k;
        q[i].x--;q[i].y--;q[i].idx=i;
    }
    sort(q,q+M,comp);
    vector<ii> mono_stack;
    bool ans[M];
    REP(i,0,M) {
        REP(j,(i?(q[i-1].y+1):0),q[i].y+1) {
            auto it=lower_bound(mono_stack.begin(),mono_stack.end(),mp(W[j],1e9),greater<ii>());
            if(it!=mono_stack.begin()) {
                it--; root->up((*it).se,(*it).fi+W[j]);
            }
            while(mono_stack.size()&&mono_stack.back().fi<=W[j]) mono_stack.pop_back();
            mono_stack.pb(mp(W[j],j));
        }
        ans[q[i].idx]=root->qry(q[i].x,N-1)<=q[i].k;
    }
    REP(i,0,M) cout << (ans[i]?1:0) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 848 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 5 ms 972 KB Output is correct
15 Correct 4 ms 980 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 5 ms 980 KB Output is correct
18 Correct 5 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1283 ms 148700 KB Output is correct
2 Correct 1284 ms 149704 KB Output is correct
3 Correct 1315 ms 149440 KB Output is correct
4 Correct 1259 ms 149652 KB Output is correct
5 Correct 1109 ms 149572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 13904 KB Output is correct
2 Correct 79 ms 13880 KB Output is correct
3 Correct 78 ms 13816 KB Output is correct
4 Correct 75 ms 13900 KB Output is correct
5 Correct 73 ms 14028 KB Output is correct
6 Correct 61 ms 13680 KB Output is correct
7 Correct 61 ms 13716 KB Output is correct
8 Correct 70 ms 13680 KB Output is correct
9 Correct 37 ms 3452 KB Output is correct
10 Correct 66 ms 13560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 848 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 5 ms 972 KB Output is correct
15 Correct 4 ms 980 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 5 ms 980 KB Output is correct
18 Correct 5 ms 980 KB Output is correct
19 Correct 226 ms 30184 KB Output is correct
20 Correct 207 ms 30188 KB Output is correct
21 Correct 179 ms 29928 KB Output is correct
22 Correct 177 ms 30024 KB Output is correct
23 Correct 190 ms 30028 KB Output is correct
24 Correct 153 ms 29836 KB Output is correct
25 Correct 168 ms 29840 KB Output is correct
26 Correct 191 ms 30156 KB Output is correct
27 Correct 178 ms 30104 KB Output is correct
28 Correct 187 ms 30028 KB Output is correct
29 Correct 211 ms 30112 KB Output is correct
30 Correct 202 ms 30100 KB Output is correct
31 Correct 205 ms 30184 KB Output is correct
32 Correct 212 ms 30152 KB Output is correct
33 Correct 193 ms 30100 KB Output is correct
34 Correct 205 ms 29808 KB Output is correct
35 Correct 170 ms 29776 KB Output is correct
36 Correct 135 ms 29524 KB Output is correct
37 Correct 139 ms 29532 KB Output is correct
38 Correct 141 ms 29776 KB Output is correct
39 Correct 170 ms 28820 KB Output is correct
40 Correct 141 ms 21380 KB Output is correct
41 Correct 169 ms 28316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 3 ms 848 KB Output is correct
13 Correct 3 ms 852 KB Output is correct
14 Correct 5 ms 972 KB Output is correct
15 Correct 4 ms 980 KB Output is correct
16 Correct 4 ms 980 KB Output is correct
17 Correct 5 ms 980 KB Output is correct
18 Correct 5 ms 980 KB Output is correct
19 Correct 1283 ms 148700 KB Output is correct
20 Correct 1284 ms 149704 KB Output is correct
21 Correct 1315 ms 149440 KB Output is correct
22 Correct 1259 ms 149652 KB Output is correct
23 Correct 1109 ms 149572 KB Output is correct
24 Correct 100 ms 13904 KB Output is correct
25 Correct 79 ms 13880 KB Output is correct
26 Correct 78 ms 13816 KB Output is correct
27 Correct 75 ms 13900 KB Output is correct
28 Correct 73 ms 14028 KB Output is correct
29 Correct 61 ms 13680 KB Output is correct
30 Correct 61 ms 13716 KB Output is correct
31 Correct 70 ms 13680 KB Output is correct
32 Correct 37 ms 3452 KB Output is correct
33 Correct 66 ms 13560 KB Output is correct
34 Correct 226 ms 30184 KB Output is correct
35 Correct 207 ms 30188 KB Output is correct
36 Correct 179 ms 29928 KB Output is correct
37 Correct 177 ms 30024 KB Output is correct
38 Correct 190 ms 30028 KB Output is correct
39 Correct 153 ms 29836 KB Output is correct
40 Correct 168 ms 29840 KB Output is correct
41 Correct 191 ms 30156 KB Output is correct
42 Correct 178 ms 30104 KB Output is correct
43 Correct 187 ms 30028 KB Output is correct
44 Correct 211 ms 30112 KB Output is correct
45 Correct 202 ms 30100 KB Output is correct
46 Correct 205 ms 30184 KB Output is correct
47 Correct 212 ms 30152 KB Output is correct
48 Correct 193 ms 30100 KB Output is correct
49 Correct 205 ms 29808 KB Output is correct
50 Correct 170 ms 29776 KB Output is correct
51 Correct 135 ms 29524 KB Output is correct
52 Correct 139 ms 29532 KB Output is correct
53 Correct 141 ms 29776 KB Output is correct
54 Correct 170 ms 28820 KB Output is correct
55 Correct 141 ms 21380 KB Output is correct
56 Correct 169 ms 28316 KB Output is correct
57 Correct 1332 ms 150232 KB Output is correct
58 Correct 1276 ms 150264 KB Output is correct
59 Correct 1195 ms 150120 KB Output is correct
60 Correct 1267 ms 150144 KB Output is correct
61 Correct 1210 ms 150136 KB Output is correct
62 Correct 1193 ms 150212 KB Output is correct
63 Correct 783 ms 148376 KB Output is correct
64 Correct 753 ms 148452 KB Output is correct
65 Correct 1028 ms 150096 KB Output is correct
66 Correct 1036 ms 150116 KB Output is correct
67 Correct 1029 ms 149952 KB Output is correct
68 Correct 1158 ms 150016 KB Output is correct
69 Correct 1129 ms 150004 KB Output is correct
70 Correct 1112 ms 149776 KB Output is correct
71 Correct 1150 ms 150048 KB Output is correct
72 Correct 1132 ms 150064 KB Output is correct
73 Correct 702 ms 146852 KB Output is correct
74 Correct 741 ms 147668 KB Output is correct
75 Correct 685 ms 146724 KB Output is correct
76 Correct 729 ms 146656 KB Output is correct
77 Correct 696 ms 146764 KB Output is correct
78 Correct 951 ms 144156 KB Output is correct
79 Correct 702 ms 92844 KB Output is correct
80 Correct 968 ms 141320 KB Output is correct