Submission #802475

# Submission time Handle Problem Language Result Execution time Memory
802475 2023-08-02T12:27:18 Z Ahmed57 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1604 ms 67364 KB
#include<bits/stdc++.h>

using namespace std;
struct query{
    int id,l,r,mood;
};
bool comp(query a, query b){
    return a.l>b.l;
}
//BIT Fenwick tree
int n ;
long long bit[1000001]={0};
void add(int e,long long v){
    while(e<=n){
        bit[e] = max(bit[e],v);
        e+=e&-e;
    }
}
long long sum(int e){
    long long res = 0;
    while(e>=1){
        res=max(res,bit[e]);
        e -= e&-e;
    }
    return res;
}
//end BIT
int main(){
	int q;
	cin>>n>>q;
	int arr[n+1];
    for(int i = 1;i<=n;i++)cin>>arr[i];
    vector<query> v;
    for(int i = 1;i<=q;i++){
        query tmp;
        cin>>tmp.l>>tmp.r>>tmp.mood;
        tmp.id = i;
        v.push_back(tmp);
    }
    sort(v.begin(),v.end(),comp);
    int now = n;
    stack<int> st;
    int ans[q+1];
    for(auto qu:v){
        while(now>=qu.l){
            while(st.size()&&arr[now]>arr[st.top()]){
                add(st.top(),arr[st.top()]+arr[now]);
                st.pop();
            }
            while(st.size()&&arr[now]==arr[st.top()])st.pop();
            st.push(now);
            now--;
        }
        ans[qu.id] = (sum(qu.r)<=qu.mood);
    }
    for(int i = 1;i<=q;i++){
        cout<<ans[i]<<"\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 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 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 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 6 ms 596 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 6 ms 500 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1604 ms 33712 KB Output is correct
2 Correct 1218 ms 66624 KB Output is correct
3 Correct 1214 ms 66488 KB Output is correct
4 Correct 1241 ms 66636 KB Output is correct
5 Correct 1169 ms 62760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 3656 KB Output is correct
2 Correct 87 ms 3668 KB Output is correct
3 Correct 93 ms 2888 KB Output is correct
4 Correct 86 ms 2892 KB Output is correct
5 Correct 86 ms 2928 KB Output is correct
6 Correct 85 ms 2968 KB Output is correct
7 Correct 93 ms 3020 KB Output is correct
8 Correct 79 ms 3000 KB Output is correct
9 Correct 60 ms 2524 KB Output is correct
10 Correct 81 ms 2952 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 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 6 ms 596 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 6 ms 500 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 254 ms 7028 KB Output is correct
20 Correct 236 ms 7188 KB Output is correct
21 Correct 226 ms 7044 KB Output is correct
22 Correct 229 ms 7060 KB Output is correct
23 Correct 230 ms 6988 KB Output is correct
24 Correct 233 ms 6160 KB Output is correct
25 Correct 236 ms 6172 KB Output is correct
26 Correct 223 ms 6176 KB Output is correct
27 Correct 230 ms 6208 KB Output is correct
28 Correct 228 ms 6168 KB Output is correct
29 Correct 267 ms 6224 KB Output is correct
30 Correct 239 ms 6168 KB Output is correct
31 Correct 224 ms 6168 KB Output is correct
32 Correct 243 ms 6124 KB Output is correct
33 Correct 224 ms 6156 KB Output is correct
34 Correct 222 ms 6232 KB Output is correct
35 Correct 211 ms 6220 KB Output is correct
36 Correct 211 ms 6256 KB Output is correct
37 Correct 225 ms 6304 KB Output is correct
38 Correct 216 ms 6172 KB Output is correct
39 Correct 203 ms 6464 KB Output is correct
40 Correct 171 ms 5736 KB Output is correct
41 Correct 182 ms 5512 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 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 4 ms 340 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 6 ms 596 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 6 ms 500 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 4 ms 468 KB Output is correct
19 Correct 1604 ms 33712 KB Output is correct
20 Correct 1218 ms 66624 KB Output is correct
21 Correct 1214 ms 66488 KB Output is correct
22 Correct 1241 ms 66636 KB Output is correct
23 Correct 1169 ms 62760 KB Output is correct
24 Correct 89 ms 3656 KB Output is correct
25 Correct 87 ms 3668 KB Output is correct
26 Correct 93 ms 2888 KB Output is correct
27 Correct 86 ms 2892 KB Output is correct
28 Correct 86 ms 2928 KB Output is correct
29 Correct 85 ms 2968 KB Output is correct
30 Correct 93 ms 3020 KB Output is correct
31 Correct 79 ms 3000 KB Output is correct
32 Correct 60 ms 2524 KB Output is correct
33 Correct 81 ms 2952 KB Output is correct
34 Correct 254 ms 7028 KB Output is correct
35 Correct 236 ms 7188 KB Output is correct
36 Correct 226 ms 7044 KB Output is correct
37 Correct 229 ms 7060 KB Output is correct
38 Correct 230 ms 6988 KB Output is correct
39 Correct 233 ms 6160 KB Output is correct
40 Correct 236 ms 6172 KB Output is correct
41 Correct 223 ms 6176 KB Output is correct
42 Correct 230 ms 6208 KB Output is correct
43 Correct 228 ms 6168 KB Output is correct
44 Correct 267 ms 6224 KB Output is correct
45 Correct 239 ms 6168 KB Output is correct
46 Correct 224 ms 6168 KB Output is correct
47 Correct 243 ms 6124 KB Output is correct
48 Correct 224 ms 6156 KB Output is correct
49 Correct 222 ms 6232 KB Output is correct
50 Correct 211 ms 6220 KB Output is correct
51 Correct 211 ms 6256 KB Output is correct
52 Correct 225 ms 6304 KB Output is correct
53 Correct 216 ms 6172 KB Output is correct
54 Correct 203 ms 6464 KB Output is correct
55 Correct 171 ms 5736 KB Output is correct
56 Correct 182 ms 5512 KB Output is correct
57 Correct 1221 ms 67364 KB Output is correct
58 Correct 1254 ms 67352 KB Output is correct
59 Correct 1214 ms 67224 KB Output is correct
60 Correct 1329 ms 67112 KB Output is correct
61 Correct 1507 ms 67244 KB Output is correct
62 Correct 1237 ms 67168 KB Output is correct
63 Correct 1157 ms 61472 KB Output is correct
64 Correct 1160 ms 61520 KB Output is correct
65 Correct 1208 ms 63352 KB Output is correct
66 Correct 1257 ms 63372 KB Output is correct
67 Correct 1216 ms 63316 KB Output is correct
68 Correct 1176 ms 63504 KB Output is correct
69 Correct 1261 ms 63504 KB Output is correct
70 Correct 1163 ms 63444 KB Output is correct
71 Correct 1207 ms 63492 KB Output is correct
72 Correct 1244 ms 63456 KB Output is correct
73 Correct 1061 ms 60064 KB Output is correct
74 Correct 1095 ms 61124 KB Output is correct
75 Correct 1082 ms 60020 KB Output is correct
76 Correct 1066 ms 60004 KB Output is correct
77 Correct 1062 ms 60048 KB Output is correct
78 Correct 1070 ms 58668 KB Output is correct
79 Correct 857 ms 49192 KB Output is correct
80 Correct 1008 ms 50596 KB Output is correct