# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
345512 | 2021-01-07T14:10:41 Z | georgerapeanu | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++11 | 1572 ms | 68864 KB |
#include <cstdio> #include <vector> #include <algorithm> using namespace std; const int NMAX = 1e6; const int QMAX = 1e6; vector<pair<int,int> > queries[NMAX + 5]; int n,q; int v[NMAX + 5]; int ans[QMAX + 5]; int w[NMAX + 5]; int aint[2 * NMAX + 5]; void update(int p,int val){ p += n; aint[p] = max(aint[p],val); for(;p > 1;p >>= 1){ aint[p >> 1] = max(aint[p],aint[p ^ 1]); } } int query(int l,int r){ r++; int ans = 0; for(l += n,r += n;l < r;l >>= 1,r >>= 1){ if(l & 1){ ans = max(ans,aint[l++]); } if(r & 1){ ans = max(ans,aint[--r]); } } return ans; } int main(){ scanf("%d %d",&n,&q); for(int i = 1;i <= n;i++){ scanf("%d",&v[i]); } for(int i = 1;i <= q;i++){ int l,r; scanf("%d %d %d",&l,&r,&w[i]); queries[r].push_back({l,i}); } vector<int> st; for(int i = 1;i <= n;i++){ while(st.empty() == false && v[st.back()] <= v[i]){ st.pop_back(); } if(st.empty() == false){ update(st.back(),v[st.back()] + v[i]); } st.push_back(i); for(auto it:queries[i]){ ans[it.second] = query(it.first,i); } } for(int i = 1;i <= q;i++){ printf("%d\n",(ans[i] <= w[i])); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 23788 KB | Output is correct |
2 | Correct | 19 ms | 23788 KB | Output is correct |
3 | Correct | 16 ms | 23884 KB | Output is correct |
4 | Correct | 18 ms | 23788 KB | Output is correct |
5 | Correct | 17 ms | 23788 KB | Output is correct |
6 | Correct | 16 ms | 23788 KB | Output is correct |
7 | Correct | 17 ms | 23788 KB | Output is correct |
8 | Correct | 16 ms | 23788 KB | Output is correct |
9 | Correct | 17 ms | 23788 KB | Output is correct |
10 | Correct | 17 ms | 23788 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 23788 KB | Output is correct |
2 | Correct | 19 ms | 23788 KB | Output is correct |
3 | Correct | 16 ms | 23884 KB | Output is correct |
4 | Correct | 18 ms | 23788 KB | Output is correct |
5 | Correct | 17 ms | 23788 KB | Output is correct |
6 | Correct | 16 ms | 23788 KB | Output is correct |
7 | Correct | 17 ms | 23788 KB | Output is correct |
8 | Correct | 16 ms | 23788 KB | Output is correct |
9 | Correct | 17 ms | 23788 KB | Output is correct |
10 | Correct | 17 ms | 23788 KB | Output is correct |
11 | Correct | 19 ms | 24036 KB | Output is correct |
12 | Correct | 22 ms | 24044 KB | Output is correct |
13 | Correct | 18 ms | 24044 KB | Output is correct |
14 | Correct | 21 ms | 24172 KB | Output is correct |
15 | Correct | 19 ms | 24172 KB | Output is correct |
16 | Correct | 22 ms | 24044 KB | Output is correct |
17 | Correct | 18 ms | 24044 KB | Output is correct |
18 | Correct | 21 ms | 24044 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1316 ms | 65268 KB | Output is correct |
2 | Correct | 1312 ms | 65216 KB | Output is correct |
3 | Correct | 1363 ms | 65284 KB | Output is correct |
4 | Correct | 1424 ms | 65252 KB | Output is correct |
5 | Correct | 1161 ms | 57396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 134 ms | 27884 KB | Output is correct |
2 | Correct | 118 ms | 29292 KB | Output is correct |
3 | Correct | 126 ms | 28908 KB | Output is correct |
4 | Correct | 102 ms | 29036 KB | Output is correct |
5 | Correct | 96 ms | 29036 KB | Output is correct |
6 | Correct | 79 ms | 28140 KB | Output is correct |
7 | Correct | 82 ms | 28140 KB | Output is correct |
8 | Correct | 106 ms | 28684 KB | Output is correct |
9 | Correct | 69 ms | 27072 KB | Output is correct |
10 | Correct | 110 ms | 28592 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 23788 KB | Output is correct |
2 | Correct | 19 ms | 23788 KB | Output is correct |
3 | Correct | 16 ms | 23884 KB | Output is correct |
4 | Correct | 18 ms | 23788 KB | Output is correct |
5 | Correct | 17 ms | 23788 KB | Output is correct |
6 | Correct | 16 ms | 23788 KB | Output is correct |
7 | Correct | 17 ms | 23788 KB | Output is correct |
8 | Correct | 16 ms | 23788 KB | Output is correct |
9 | Correct | 17 ms | 23788 KB | Output is correct |
10 | Correct | 17 ms | 23788 KB | Output is correct |
11 | Correct | 19 ms | 24036 KB | Output is correct |
12 | Correct | 22 ms | 24044 KB | Output is correct |
13 | Correct | 18 ms | 24044 KB | Output is correct |
14 | Correct | 21 ms | 24172 KB | Output is correct |
15 | Correct | 19 ms | 24172 KB | Output is correct |
16 | Correct | 22 ms | 24044 KB | Output is correct |
17 | Correct | 18 ms | 24044 KB | Output is correct |
18 | Correct | 21 ms | 24044 KB | Output is correct |
19 | Correct | 250 ms | 38252 KB | Output is correct |
20 | Correct | 235 ms | 38252 KB | Output is correct |
21 | Correct | 195 ms | 37228 KB | Output is correct |
22 | Correct | 214 ms | 37228 KB | Output is correct |
23 | Correct | 207 ms | 37100 KB | Output is correct |
24 | Correct | 191 ms | 35436 KB | Output is correct |
25 | Correct | 225 ms | 35436 KB | Output is correct |
26 | Correct | 214 ms | 35948 KB | Output is correct |
27 | Correct | 217 ms | 35940 KB | Output is correct |
28 | Correct | 218 ms | 36168 KB | Output is correct |
29 | Correct | 243 ms | 36716 KB | Output is correct |
30 | Correct | 237 ms | 36844 KB | Output is correct |
31 | Correct | 259 ms | 36716 KB | Output is correct |
32 | Correct | 237 ms | 36628 KB | Output is correct |
33 | Correct | 261 ms | 36716 KB | Output is correct |
34 | Correct | 170 ms | 35052 KB | Output is correct |
35 | Correct | 185 ms | 35052 KB | Output is correct |
36 | Correct | 168 ms | 34924 KB | Output is correct |
37 | Correct | 171 ms | 34868 KB | Output is correct |
38 | Correct | 219 ms | 35200 KB | Output is correct |
39 | Correct | 219 ms | 35684 KB | Output is correct |
40 | Correct | 224 ms | 33888 KB | Output is correct |
41 | Correct | 217 ms | 34784 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 23788 KB | Output is correct |
2 | Correct | 19 ms | 23788 KB | Output is correct |
3 | Correct | 16 ms | 23884 KB | Output is correct |
4 | Correct | 18 ms | 23788 KB | Output is correct |
5 | Correct | 17 ms | 23788 KB | Output is correct |
6 | Correct | 16 ms | 23788 KB | Output is correct |
7 | Correct | 17 ms | 23788 KB | Output is correct |
8 | Correct | 16 ms | 23788 KB | Output is correct |
9 | Correct | 17 ms | 23788 KB | Output is correct |
10 | Correct | 17 ms | 23788 KB | Output is correct |
11 | Correct | 19 ms | 24036 KB | Output is correct |
12 | Correct | 22 ms | 24044 KB | Output is correct |
13 | Correct | 18 ms | 24044 KB | Output is correct |
14 | Correct | 21 ms | 24172 KB | Output is correct |
15 | Correct | 19 ms | 24172 KB | Output is correct |
16 | Correct | 22 ms | 24044 KB | Output is correct |
17 | Correct | 18 ms | 24044 KB | Output is correct |
18 | Correct | 21 ms | 24044 KB | Output is correct |
19 | Correct | 1316 ms | 65268 KB | Output is correct |
20 | Correct | 1312 ms | 65216 KB | Output is correct |
21 | Correct | 1363 ms | 65284 KB | Output is correct |
22 | Correct | 1424 ms | 65252 KB | Output is correct |
23 | Correct | 1161 ms | 57396 KB | Output is correct |
24 | Correct | 134 ms | 27884 KB | Output is correct |
25 | Correct | 118 ms | 29292 KB | Output is correct |
26 | Correct | 126 ms | 28908 KB | Output is correct |
27 | Correct | 102 ms | 29036 KB | Output is correct |
28 | Correct | 96 ms | 29036 KB | Output is correct |
29 | Correct | 79 ms | 28140 KB | Output is correct |
30 | Correct | 82 ms | 28140 KB | Output is correct |
31 | Correct | 106 ms | 28684 KB | Output is correct |
32 | Correct | 69 ms | 27072 KB | Output is correct |
33 | Correct | 110 ms | 28592 KB | Output is correct |
34 | Correct | 250 ms | 38252 KB | Output is correct |
35 | Correct | 235 ms | 38252 KB | Output is correct |
36 | Correct | 195 ms | 37228 KB | Output is correct |
37 | Correct | 214 ms | 37228 KB | Output is correct |
38 | Correct | 207 ms | 37100 KB | Output is correct |
39 | Correct | 191 ms | 35436 KB | Output is correct |
40 | Correct | 225 ms | 35436 KB | Output is correct |
41 | Correct | 214 ms | 35948 KB | Output is correct |
42 | Correct | 217 ms | 35940 KB | Output is correct |
43 | Correct | 218 ms | 36168 KB | Output is correct |
44 | Correct | 243 ms | 36716 KB | Output is correct |
45 | Correct | 237 ms | 36844 KB | Output is correct |
46 | Correct | 259 ms | 36716 KB | Output is correct |
47 | Correct | 237 ms | 36628 KB | Output is correct |
48 | Correct | 261 ms | 36716 KB | Output is correct |
49 | Correct | 170 ms | 35052 KB | Output is correct |
50 | Correct | 185 ms | 35052 KB | Output is correct |
51 | Correct | 168 ms | 34924 KB | Output is correct |
52 | Correct | 171 ms | 34868 KB | Output is correct |
53 | Correct | 219 ms | 35200 KB | Output is correct |
54 | Correct | 219 ms | 35684 KB | Output is correct |
55 | Correct | 224 ms | 33888 KB | Output is correct |
56 | Correct | 217 ms | 34784 KB | Output is correct |
57 | Correct | 1529 ms | 68864 KB | Output is correct |
58 | Correct | 1306 ms | 64704 KB | Output is correct |
59 | Correct | 1461 ms | 62088 KB | Output is correct |
60 | Correct | 1572 ms | 61968 KB | Output is correct |
61 | Correct | 1386 ms | 61956 KB | Output is correct |
62 | Correct | 1213 ms | 62024 KB | Output is correct |
63 | Correct | 876 ms | 50688 KB | Output is correct |
64 | Correct | 869 ms | 50416 KB | Output is correct |
65 | Correct | 1171 ms | 54020 KB | Output is correct |
66 | Correct | 1151 ms | 53992 KB | Output is correct |
67 | Correct | 1209 ms | 54140 KB | Output is correct |
68 | Correct | 1278 ms | 56936 KB | Output is correct |
69 | Correct | 1324 ms | 56956 KB | Output is correct |
70 | Correct | 1349 ms | 56452 KB | Output is correct |
71 | Correct | 1293 ms | 56448 KB | Output is correct |
72 | Correct | 1294 ms | 56404 KB | Output is correct |
73 | Correct | 787 ms | 48748 KB | Output is correct |
74 | Correct | 779 ms | 48748 KB | Output is correct |
75 | Correct | 825 ms | 48968 KB | Output is correct |
76 | Correct | 765 ms | 48880 KB | Output is correct |
77 | Correct | 974 ms | 48620 KB | Output is correct |
78 | Correct | 1138 ms | 57472 KB | Output is correct |
79 | Correct | 950 ms | 50796 KB | Output is correct |
80 | Correct | 1128 ms | 55124 KB | Output is correct |