Submission #588486

# Submission time Handle Problem Language Result Execution time Memory
588486 2022-07-03T11:10:03 Z AmirElarbi Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2635 ms 104688 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e4+7;
const int nax = 1e6+5;
typedef complex<int> Point;
#define X real()
#define Y imag()
int st[nax*4];
void update(int v, int l, int r, int pos, int val){
    if(l > pos || r < pos) return;
    if(l == r){
        st[v] = val;
        return;
    } 
    int md = (l+r)/2;
    update(v*2,l,md,pos,val);
    update(v*2+1,md+1,r,pos,val);
    st[v] = max(st[v*2], st[v*2+1]);
}
int query(int v, int l, int r, int i, int j){
    if(l > j || r < i) return 0;
    if(i <= l && r <= j) return st[v];
    int md = (l+r)/2;
    return max(query(v*2,l,md,i,j), query(v*2+1, md+1, r, i, j));
}
int main(){
    optimise;
    int t;
    t = 1;
    while(t--){
        int n,q;
        cin >> n >> q;
        vi s(n),l(q), r(q), k(q), ans(q);
        vvi qrs(n);
        for (int i = 0; i < n; ++i)
        {
            cin >> s[i];
        }
        for (int i = 0; i < q; ++i)
        {
            cin >> l[i] >> r[i] >> k[i];
            l[i]--,r[i]--;
            qrs[r[i]].pb(i);
        }
        stack<int> stck;
        for (int i = 0; i < n; ++i)
        {
            while(!stck.empty() && s[stck.top()] <= s[i]){
                stck.pop();    
            }
            if(!stck.empty()) {
                update(1,0,n-1, stck.top(), s[stck.top()]+s[i]);
            }
            stck.push(i);
            for(auto x : qrs[i]){
                ans[x] = (query(1,0,n-1,l[x],i) <= k[x]);
            }
        }
        for (int i = 0; i < q; ++i)
        {
            cout << ans[i] << endl;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 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 6 ms 468 KB Output is correct
12 Correct 7 ms 724 KB Output is correct
13 Correct 6 ms 744 KB Output is correct
14 Correct 11 ms 852 KB Output is correct
15 Correct 11 ms 852 KB Output is correct
16 Correct 10 ms 720 KB Output is correct
17 Correct 8 ms 596 KB Output is correct
18 Correct 9 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2625 ms 80600 KB Output is correct
2 Correct 2526 ms 104688 KB Output is correct
3 Correct 2506 ms 104356 KB Output is correct
4 Correct 2569 ms 104460 KB Output is correct
5 Correct 2196 ms 96212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 9424 KB Output is correct
2 Correct 190 ms 8588 KB Output is correct
3 Correct 189 ms 8076 KB Output is correct
4 Correct 193 ms 8288 KB Output is correct
5 Correct 189 ms 8372 KB Output is correct
6 Correct 179 ms 7276 KB Output is correct
7 Correct 171 ms 7244 KB Output is correct
8 Correct 174 ms 8080 KB Output is correct
9 Correct 147 ms 3816 KB Output is correct
10 Correct 194 ms 8048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 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 6 ms 468 KB Output is correct
12 Correct 7 ms 724 KB Output is correct
13 Correct 6 ms 744 KB Output is correct
14 Correct 11 ms 852 KB Output is correct
15 Correct 11 ms 852 KB Output is correct
16 Correct 10 ms 720 KB Output is correct
17 Correct 8 ms 596 KB Output is correct
18 Correct 9 ms 728 KB Output is correct
19 Correct 450 ms 21184 KB Output is correct
20 Correct 430 ms 21100 KB Output is correct
21 Correct 425 ms 19356 KB Output is correct
22 Correct 465 ms 19472 KB Output is correct
23 Correct 427 ms 19324 KB Output is correct
24 Correct 388 ms 17128 KB Output is correct
25 Correct 413 ms 17008 KB Output is correct
26 Correct 391 ms 17856 KB Output is correct
27 Correct 406 ms 18052 KB Output is correct
28 Correct 426 ms 18316 KB Output is correct
29 Correct 418 ms 19244 KB Output is correct
30 Correct 397 ms 19160 KB Output is correct
31 Correct 399 ms 19132 KB Output is correct
32 Correct 402 ms 19076 KB Output is correct
33 Correct 442 ms 19044 KB Output is correct
34 Correct 351 ms 16740 KB Output is correct
35 Correct 377 ms 16712 KB Output is correct
36 Correct 360 ms 16524 KB Output is correct
37 Correct 347 ms 16440 KB Output is correct
38 Correct 377 ms 16616 KB Output is correct
39 Correct 387 ms 18112 KB Output is correct
40 Correct 357 ms 14580 KB Output is correct
41 Correct 382 ms 17212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 328 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 6 ms 468 KB Output is correct
12 Correct 7 ms 724 KB Output is correct
13 Correct 6 ms 744 KB Output is correct
14 Correct 11 ms 852 KB Output is correct
15 Correct 11 ms 852 KB Output is correct
16 Correct 10 ms 720 KB Output is correct
17 Correct 8 ms 596 KB Output is correct
18 Correct 9 ms 728 KB Output is correct
19 Correct 2625 ms 80600 KB Output is correct
20 Correct 2526 ms 104688 KB Output is correct
21 Correct 2506 ms 104356 KB Output is correct
22 Correct 2569 ms 104460 KB Output is correct
23 Correct 2196 ms 96212 KB Output is correct
24 Correct 215 ms 9424 KB Output is correct
25 Correct 190 ms 8588 KB Output is correct
26 Correct 189 ms 8076 KB Output is correct
27 Correct 193 ms 8288 KB Output is correct
28 Correct 189 ms 8372 KB Output is correct
29 Correct 179 ms 7276 KB Output is correct
30 Correct 171 ms 7244 KB Output is correct
31 Correct 174 ms 8080 KB Output is correct
32 Correct 147 ms 3816 KB Output is correct
33 Correct 194 ms 8048 KB Output is correct
34 Correct 450 ms 21184 KB Output is correct
35 Correct 430 ms 21100 KB Output is correct
36 Correct 425 ms 19356 KB Output is correct
37 Correct 465 ms 19472 KB Output is correct
38 Correct 427 ms 19324 KB Output is correct
39 Correct 388 ms 17128 KB Output is correct
40 Correct 413 ms 17008 KB Output is correct
41 Correct 391 ms 17856 KB Output is correct
42 Correct 406 ms 18052 KB Output is correct
43 Correct 426 ms 18316 KB Output is correct
44 Correct 418 ms 19244 KB Output is correct
45 Correct 397 ms 19160 KB Output is correct
46 Correct 399 ms 19132 KB Output is correct
47 Correct 402 ms 19076 KB Output is correct
48 Correct 442 ms 19044 KB Output is correct
49 Correct 351 ms 16740 KB Output is correct
50 Correct 377 ms 16712 KB Output is correct
51 Correct 360 ms 16524 KB Output is correct
52 Correct 347 ms 16440 KB Output is correct
53 Correct 377 ms 16616 KB Output is correct
54 Correct 387 ms 18112 KB Output is correct
55 Correct 357 ms 14580 KB Output is correct
56 Correct 382 ms 17212 KB Output is correct
57 Correct 2635 ms 103304 KB Output is correct
58 Correct 2476 ms 103340 KB Output is correct
59 Correct 2418 ms 99096 KB Output is correct
60 Correct 2452 ms 99116 KB Output is correct
61 Correct 2486 ms 99108 KB Output is correct
62 Correct 2432 ms 99144 KB Output is correct
63 Correct 1929 ms 83292 KB Output is correct
64 Correct 1945 ms 83268 KB Output is correct
65 Correct 2165 ms 90520 KB Output is correct
66 Correct 2270 ms 90552 KB Output is correct
67 Correct 2192 ms 89820 KB Output is correct
68 Correct 2222 ms 95224 KB Output is correct
69 Correct 2243 ms 95216 KB Output is correct
70 Correct 2186 ms 94488 KB Output is correct
71 Correct 2293 ms 93924 KB Output is correct
72 Correct 2437 ms 94020 KB Output is correct
73 Correct 2208 ms 81320 KB Output is correct
74 Correct 2075 ms 82160 KB Output is correct
75 Correct 2005 ms 81292 KB Output is correct
76 Correct 1968 ms 81356 KB Output is correct
77 Correct 2055 ms 80296 KB Output is correct
78 Correct 2227 ms 89952 KB Output is correct
79 Correct 1888 ms 67160 KB Output is correct
80 Correct 2128 ms 85120 KB Output is correct