Submission #1032787

# Submission time Handle Problem Language Result Execution time Memory
1032787 2024-07-24T08:36:13 Z pera Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
2130 ms 75752 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1;
int n , m;
vector<int> w(N) , ans(N) , r(N) , t(4 * N);
vector<tuple<int , int , int>> query[N];
void upd(int u , int l , int r , int pos , int x){
   if(l == r){
      t[u] = x;
      return;
   }
   int m = (l + r) / 2;
   if(pos <= m){
      upd(u * 2 , l , m , pos , x);
   }else{
      upd(u * 2 + 1 , m + 1 , r , pos , x);
   }
   t[u] = max(t[u * 2] , t[u * 2 + 1]);
}
int GET(int u , int l , int r , int L , int R){
   if(l > r || r < L || l > R){
      return 0;
   }
   if(L <= l && r <= R){
      return t[u];
   }
   int m = (l + r) / 2;
   return max(GET(u * 2 , l , m , L , R) , GET(u * 2 + 1 , m + 1 , r , L , R));
}
int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin >> n >> m;
   for(int i = 1;i <= n;i ++){
      cin >> w[i];
   }
   for(int i = 1;i <= m;i ++){
      int l , r , k;
      cin >> l >> r >> k;
      query[l].push_back({r , k , i});
   }
   for(int i = n;i >= 1;i --){
      r[i] = i + 1;
      while(r[i] <= n && w[i] > w[r[i]]){
         upd(1 , 1 , n , r[i] , w[r[i]] + w[i]);
         r[i] = r[r[i]];
      }
      for(auto [r , k , id] : query[i]){
         ans[id] = GET(1 , 1 , n , i , r) <= k;
      }
   }
   for(int i = 1;i <= m;i ++){
      cout << ans[i] << endl;
   }
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51288 KB Output is correct
2 Correct 18 ms 51288 KB Output is correct
3 Correct 19 ms 51292 KB Output is correct
4 Correct 19 ms 51124 KB Output is correct
5 Correct 18 ms 51292 KB Output is correct
6 Correct 19 ms 51292 KB Output is correct
7 Correct 18 ms 51544 KB Output is correct
8 Correct 33 ms 51324 KB Output is correct
9 Correct 20 ms 51300 KB Output is correct
10 Correct 19 ms 51292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51288 KB Output is correct
2 Correct 18 ms 51288 KB Output is correct
3 Correct 19 ms 51292 KB Output is correct
4 Correct 19 ms 51124 KB Output is correct
5 Correct 18 ms 51292 KB Output is correct
6 Correct 19 ms 51292 KB Output is correct
7 Correct 18 ms 51544 KB Output is correct
8 Correct 33 ms 51324 KB Output is correct
9 Correct 20 ms 51300 KB Output is correct
10 Correct 19 ms 51292 KB Output is correct
11 Correct 36 ms 51288 KB Output is correct
12 Correct 22 ms 51292 KB Output is correct
13 Correct 23 ms 51292 KB Output is correct
14 Correct 42 ms 51280 KB Output is correct
15 Correct 21 ms 51288 KB Output is correct
16 Correct 21 ms 51292 KB Output is correct
17 Correct 24 ms 51464 KB Output is correct
18 Correct 25 ms 51292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2032 ms 74848 KB Output is correct
2 Correct 2003 ms 74932 KB Output is correct
3 Correct 1881 ms 74924 KB Output is correct
4 Correct 2130 ms 74836 KB Output is correct
5 Correct 1946 ms 74836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 189 ms 53592 KB Output is correct
2 Correct 225 ms 53744 KB Output is correct
3 Correct 189 ms 53460 KB Output is correct
4 Correct 174 ms 53584 KB Output is correct
5 Correct 181 ms 53588 KB Output is correct
6 Correct 189 ms 53076 KB Output is correct
7 Correct 149 ms 53064 KB Output is correct
8 Correct 155 ms 53440 KB Output is correct
9 Correct 159 ms 53004 KB Output is correct
10 Correct 201 ms 53388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51288 KB Output is correct
2 Correct 18 ms 51288 KB Output is correct
3 Correct 19 ms 51292 KB Output is correct
4 Correct 19 ms 51124 KB Output is correct
5 Correct 18 ms 51292 KB Output is correct
6 Correct 19 ms 51292 KB Output is correct
7 Correct 18 ms 51544 KB Output is correct
8 Correct 33 ms 51324 KB Output is correct
9 Correct 20 ms 51300 KB Output is correct
10 Correct 19 ms 51292 KB Output is correct
11 Correct 36 ms 51288 KB Output is correct
12 Correct 22 ms 51292 KB Output is correct
13 Correct 23 ms 51292 KB Output is correct
14 Correct 42 ms 51280 KB Output is correct
15 Correct 21 ms 51288 KB Output is correct
16 Correct 21 ms 51292 KB Output is correct
17 Correct 24 ms 51464 KB Output is correct
18 Correct 25 ms 51292 KB Output is correct
19 Correct 374 ms 56204 KB Output is correct
20 Correct 364 ms 56148 KB Output is correct
21 Correct 339 ms 55644 KB Output is correct
22 Correct 325 ms 55688 KB Output is correct
23 Correct 349 ms 56028 KB Output is correct
24 Correct 322 ms 55560 KB Output is correct
25 Correct 330 ms 55604 KB Output is correct
26 Correct 321 ms 55632 KB Output is correct
27 Correct 307 ms 55636 KB Output is correct
28 Correct 341 ms 55636 KB Output is correct
29 Correct 406 ms 56400 KB Output is correct
30 Correct 338 ms 56148 KB Output is correct
31 Correct 351 ms 56148 KB Output is correct
32 Correct 359 ms 56176 KB Output is correct
33 Correct 389 ms 56216 KB Output is correct
34 Correct 322 ms 54868 KB Output is correct
35 Correct 305 ms 55064 KB Output is correct
36 Correct 301 ms 54920 KB Output is correct
37 Correct 331 ms 55120 KB Output is correct
38 Correct 327 ms 55096 KB Output is correct
39 Correct 360 ms 55308 KB Output is correct
40 Correct 316 ms 55080 KB Output is correct
41 Correct 335 ms 55564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51288 KB Output is correct
2 Correct 18 ms 51288 KB Output is correct
3 Correct 19 ms 51292 KB Output is correct
4 Correct 19 ms 51124 KB Output is correct
5 Correct 18 ms 51292 KB Output is correct
6 Correct 19 ms 51292 KB Output is correct
7 Correct 18 ms 51544 KB Output is correct
8 Correct 33 ms 51324 KB Output is correct
9 Correct 20 ms 51300 KB Output is correct
10 Correct 19 ms 51292 KB Output is correct
11 Correct 36 ms 51288 KB Output is correct
12 Correct 22 ms 51292 KB Output is correct
13 Correct 23 ms 51292 KB Output is correct
14 Correct 42 ms 51280 KB Output is correct
15 Correct 21 ms 51288 KB Output is correct
16 Correct 21 ms 51292 KB Output is correct
17 Correct 24 ms 51464 KB Output is correct
18 Correct 25 ms 51292 KB Output is correct
19 Correct 2032 ms 74848 KB Output is correct
20 Correct 2003 ms 74932 KB Output is correct
21 Correct 1881 ms 74924 KB Output is correct
22 Correct 2130 ms 74836 KB Output is correct
23 Correct 1946 ms 74836 KB Output is correct
24 Correct 189 ms 53592 KB Output is correct
25 Correct 225 ms 53744 KB Output is correct
26 Correct 189 ms 53460 KB Output is correct
27 Correct 174 ms 53584 KB Output is correct
28 Correct 181 ms 53588 KB Output is correct
29 Correct 189 ms 53076 KB Output is correct
30 Correct 149 ms 53064 KB Output is correct
31 Correct 155 ms 53440 KB Output is correct
32 Correct 159 ms 53004 KB Output is correct
33 Correct 201 ms 53388 KB Output is correct
34 Correct 374 ms 56204 KB Output is correct
35 Correct 364 ms 56148 KB Output is correct
36 Correct 339 ms 55644 KB Output is correct
37 Correct 325 ms 55688 KB Output is correct
38 Correct 349 ms 56028 KB Output is correct
39 Correct 322 ms 55560 KB Output is correct
40 Correct 330 ms 55604 KB Output is correct
41 Correct 321 ms 55632 KB Output is correct
42 Correct 307 ms 55636 KB Output is correct
43 Correct 341 ms 55636 KB Output is correct
44 Correct 406 ms 56400 KB Output is correct
45 Correct 338 ms 56148 KB Output is correct
46 Correct 351 ms 56148 KB Output is correct
47 Correct 359 ms 56176 KB Output is correct
48 Correct 389 ms 56216 KB Output is correct
49 Correct 322 ms 54868 KB Output is correct
50 Correct 305 ms 55064 KB Output is correct
51 Correct 301 ms 54920 KB Output is correct
52 Correct 331 ms 55120 KB Output is correct
53 Correct 327 ms 55096 KB Output is correct
54 Correct 360 ms 55308 KB Output is correct
55 Correct 316 ms 55080 KB Output is correct
56 Correct 335 ms 55564 KB Output is correct
57 Correct 2079 ms 75752 KB Output is correct
58 Correct 1783 ms 75604 KB Output is correct
59 Correct 1857 ms 73624 KB Output is correct
60 Correct 1894 ms 73712 KB Output is correct
61 Correct 1770 ms 73808 KB Output is correct
62 Correct 1903 ms 73808 KB Output is correct
63 Correct 1469 ms 69972 KB Output is correct
64 Correct 1407 ms 69932 KB Output is correct
65 Correct 1658 ms 73616 KB Output is correct
66 Correct 1646 ms 73556 KB Output is correct
67 Correct 1716 ms 73760 KB Output is correct
68 Correct 1740 ms 75604 KB Output is correct
69 Correct 1771 ms 75604 KB Output is correct
70 Correct 1743 ms 75344 KB Output is correct
71 Correct 1771 ms 75148 KB Output is correct
72 Correct 1776 ms 75216 KB Output is correct
73 Correct 1473 ms 69052 KB Output is correct
74 Correct 1479 ms 68944 KB Output is correct
75 Correct 1431 ms 69020 KB Output is correct
76 Correct 1429 ms 68884 KB Output is correct
77 Correct 1467 ms 69280 KB Output is correct
78 Correct 1625 ms 71808 KB Output is correct
79 Correct 1427 ms 69680 KB Output is correct
80 Correct 1676 ms 71428 KB Output is correct