Submission #502914

# Submission time Handle Problem Language Result Execution time Memory
502914 2022-01-06T18:23:36 Z nickmet2004 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++11
100 / 100
2966 ms 99388 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6+5;
int n , q , a[N] , d[N] , ans[N];
int T[4*N];
void upd(int id , int d , int l = 1 , int r =n , int pos =1){
    if(id < l || id > r)return;
    if(l==r){
        T[pos] = d;return;
    }
    int mid = (l + r) >> 1;
    upd(id , d ,l , mid , pos * 2); upd(id ,d , mid + 1 , r ,pos * 2 + 1);
    T[pos] = max(T[pos * 2] , T[pos * 2 + 1]);
}
int get(int L ,int R , int l = 1 ,int r = n , int pos = 1){
    if(r < L || R < l)return 0;
    if(L <= l && r <= R)return T[pos];
    int mid = (l + r) >> 1;
    return max(get(L , R , l , mid , pos *2) , get(L , R , mid + 1 , r , pos * 2 + 1));
}
vector<pair<int , int> > Q[N];
 main (){
    ios_base::sync_with_stdio(0);
    cin >> n>>q;
    vector<int> K;
    for(int i = 1; i<= n; ++i)cin >> a[i];
    for(int i = 0; i < q; ++i){
        int l , r;
        cin >> l >> r>>d[i];
        Q[r].emplace_back(l , i);
    }
    stack<int> s;
    for(int R = 1; R <= n; ++R){
        while(s.size() && a[s.top()] <= a[R])s.pop();
        if(s.size()) upd(s.top() , a[R] + a[s.top()]);
        s.push(R);
        for(auto x : Q[R]){
            if(get(x.first , R) <= d[x.second])ans[x.second] = 1;
            else ans[x.second] = 0;
        }
    }
    for(int i = 0; i <q; ++i)cout << ans[i] <<endl;
    //for(int x : T[9].s)cout << x << "x ";

}

Compilation message

sortbooks.cpp:23:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   23 |  main (){
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23756 KB Output is correct
2 Correct 11 ms 23756 KB Output is correct
3 Correct 11 ms 23756 KB Output is correct
4 Correct 12 ms 23800 KB Output is correct
5 Correct 11 ms 23812 KB Output is correct
6 Correct 14 ms 23776 KB Output is correct
7 Correct 13 ms 23820 KB Output is correct
8 Correct 15 ms 23812 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23756 KB Output is correct
2 Correct 11 ms 23756 KB Output is correct
3 Correct 11 ms 23756 KB Output is correct
4 Correct 12 ms 23800 KB Output is correct
5 Correct 11 ms 23812 KB Output is correct
6 Correct 14 ms 23776 KB Output is correct
7 Correct 13 ms 23820 KB Output is correct
8 Correct 15 ms 23812 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 17 ms 24080 KB Output is correct
12 Correct 17 ms 24192 KB Output is correct
13 Correct 19 ms 24168 KB Output is correct
14 Correct 23 ms 24332 KB Output is correct
15 Correct 21 ms 24268 KB Output is correct
16 Correct 19 ms 24208 KB Output is correct
17 Correct 18 ms 24140 KB Output is correct
18 Correct 19 ms 24140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2486 ms 91896 KB Output is correct
2 Correct 2508 ms 91892 KB Output is correct
3 Correct 2634 ms 91800 KB Output is correct
4 Correct 2713 ms 92320 KB Output is correct
5 Correct 2294 ms 75736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 238 ms 31096 KB Output is correct
2 Correct 218 ms 32856 KB Output is correct
3 Correct 210 ms 30748 KB Output is correct
4 Correct 198 ms 30948 KB Output is correct
5 Correct 229 ms 30872 KB Output is correct
6 Correct 186 ms 30468 KB Output is correct
7 Correct 201 ms 30412 KB Output is correct
8 Correct 197 ms 30420 KB Output is correct
9 Correct 156 ms 28824 KB Output is correct
10 Correct 198 ms 30424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23756 KB Output is correct
2 Correct 11 ms 23756 KB Output is correct
3 Correct 11 ms 23756 KB Output is correct
4 Correct 12 ms 23800 KB Output is correct
5 Correct 11 ms 23812 KB Output is correct
6 Correct 14 ms 23776 KB Output is correct
7 Correct 13 ms 23820 KB Output is correct
8 Correct 15 ms 23812 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 17 ms 24080 KB Output is correct
12 Correct 17 ms 24192 KB Output is correct
13 Correct 19 ms 24168 KB Output is correct
14 Correct 23 ms 24332 KB Output is correct
15 Correct 21 ms 24268 KB Output is correct
16 Correct 19 ms 24208 KB Output is correct
17 Correct 18 ms 24140 KB Output is correct
18 Correct 19 ms 24140 KB Output is correct
19 Correct 512 ms 44896 KB Output is correct
20 Correct 511 ms 43716 KB Output is correct
21 Correct 445 ms 43372 KB Output is correct
22 Correct 440 ms 43388 KB Output is correct
23 Correct 438 ms 43452 KB Output is correct
24 Correct 453 ms 39380 KB Output is correct
25 Correct 404 ms 39464 KB Output is correct
26 Correct 411 ms 39296 KB Output is correct
27 Correct 393 ms 39272 KB Output is correct
28 Correct 401 ms 39524 KB Output is correct
29 Correct 413 ms 39576 KB Output is correct
30 Correct 433 ms 39588 KB Output is correct
31 Correct 423 ms 39492 KB Output is correct
32 Correct 413 ms 39512 KB Output is correct
33 Correct 418 ms 39544 KB Output is correct
34 Correct 385 ms 38964 KB Output is correct
35 Correct 400 ms 39016 KB Output is correct
36 Correct 386 ms 39068 KB Output is correct
37 Correct 379 ms 38968 KB Output is correct
38 Correct 370 ms 38932 KB Output is correct
39 Correct 404 ms 40240 KB Output is correct
40 Correct 355 ms 37148 KB Output is correct
41 Correct 382 ms 38332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23756 KB Output is correct
2 Correct 11 ms 23756 KB Output is correct
3 Correct 11 ms 23756 KB Output is correct
4 Correct 12 ms 23800 KB Output is correct
5 Correct 11 ms 23812 KB Output is correct
6 Correct 14 ms 23776 KB Output is correct
7 Correct 13 ms 23820 KB Output is correct
8 Correct 15 ms 23812 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 15 ms 23756 KB Output is correct
11 Correct 17 ms 24080 KB Output is correct
12 Correct 17 ms 24192 KB Output is correct
13 Correct 19 ms 24168 KB Output is correct
14 Correct 23 ms 24332 KB Output is correct
15 Correct 21 ms 24268 KB Output is correct
16 Correct 19 ms 24208 KB Output is correct
17 Correct 18 ms 24140 KB Output is correct
18 Correct 19 ms 24140 KB Output is correct
19 Correct 2486 ms 91896 KB Output is correct
20 Correct 2508 ms 91892 KB Output is correct
21 Correct 2634 ms 91800 KB Output is correct
22 Correct 2713 ms 92320 KB Output is correct
23 Correct 2294 ms 75736 KB Output is correct
24 Correct 238 ms 31096 KB Output is correct
25 Correct 218 ms 32856 KB Output is correct
26 Correct 210 ms 30748 KB Output is correct
27 Correct 198 ms 30948 KB Output is correct
28 Correct 229 ms 30872 KB Output is correct
29 Correct 186 ms 30468 KB Output is correct
30 Correct 201 ms 30412 KB Output is correct
31 Correct 197 ms 30420 KB Output is correct
32 Correct 156 ms 28824 KB Output is correct
33 Correct 198 ms 30424 KB Output is correct
34 Correct 512 ms 44896 KB Output is correct
35 Correct 511 ms 43716 KB Output is correct
36 Correct 445 ms 43372 KB Output is correct
37 Correct 440 ms 43388 KB Output is correct
38 Correct 438 ms 43452 KB Output is correct
39 Correct 453 ms 39380 KB Output is correct
40 Correct 404 ms 39464 KB Output is correct
41 Correct 411 ms 39296 KB Output is correct
42 Correct 393 ms 39272 KB Output is correct
43 Correct 401 ms 39524 KB Output is correct
44 Correct 413 ms 39576 KB Output is correct
45 Correct 433 ms 39588 KB Output is correct
46 Correct 423 ms 39492 KB Output is correct
47 Correct 413 ms 39512 KB Output is correct
48 Correct 418 ms 39544 KB Output is correct
49 Correct 385 ms 38964 KB Output is correct
50 Correct 400 ms 39016 KB Output is correct
51 Correct 386 ms 39068 KB Output is correct
52 Correct 379 ms 38968 KB Output is correct
53 Correct 370 ms 38932 KB Output is correct
54 Correct 404 ms 40240 KB Output is correct
55 Correct 355 ms 37148 KB Output is correct
56 Correct 382 ms 38332 KB Output is correct
57 Correct 2589 ms 99092 KB Output is correct
58 Correct 2966 ms 99376 KB Output is correct
59 Correct 2735 ms 98560 KB Output is correct
60 Correct 2571 ms 98700 KB Output is correct
61 Correct 2423 ms 99388 KB Output is correct
62 Correct 2399 ms 95884 KB Output is correct
63 Correct 1961 ms 82380 KB Output is correct
64 Correct 1914 ms 81608 KB Output is correct
65 Correct 2301 ms 79852 KB Output is correct
66 Correct 2190 ms 81628 KB Output is correct
67 Correct 2147 ms 77440 KB Output is correct
68 Correct 2213 ms 80136 KB Output is correct
69 Correct 2270 ms 81316 KB Output is correct
70 Correct 2201 ms 82008 KB Output is correct
71 Correct 2167 ms 80048 KB Output is correct
72 Correct 2187 ms 79976 KB Output is correct
73 Correct 1820 ms 75500 KB Output is correct
74 Correct 2222 ms 80148 KB Output is correct
75 Correct 2261 ms 80752 KB Output is correct
76 Correct 2131 ms 85132 KB Output is correct
77 Correct 1995 ms 85536 KB Output is correct
78 Correct 2087 ms 93688 KB Output is correct
79 Correct 1815 ms 71108 KB Output is correct
80 Correct 2066 ms 87328 KB Output is correct