Submission #932947

# Submission time Handle Problem Language Result Execution time Memory
932947 2024-02-24T15:42:59 Z beepbeepsheep Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1360 ms 114804 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<long long, null_type, less_equal<>,
        rb_tree_tag, tree_order_statistics_node_update>
        ordered_set;
#define ll long long
#define ii pair<ll,ll>

#ifndef DEBUG
#define cerr if (0) cerr
#define endl '\n'
#endif

const ll inf=1e15;
const ll maxn=1e6+5;
const ll mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

stack<ll> s;
ll arr[maxn];
ll nxt[maxn];
struct node{
	ll n;
	node(ll _n):n(_n){}
	ii tree[maxn*2];
	void upd(int i, int x){
		int ori=i;
	    i += n;
	    tree[i] = {x,ori};
	    i >>= 1;
	    while(i > 0){
	        tree[i] = max(tree[i<<1], tree[i<<1|1]);
	        i>>=1;
	    }
	}
	ii query(int l, int r){ ///[l, r] both inclusive
	    ii ans = {0,0};
	    for(l += n, r += n+1;l < r;l >>= 1, r >>= 1){
	        if(l&1){
	            ans = max(ans, tree[l]);
	            l++;
	        }
	        if(r&1){
	            r--;
	            ans = max(ans, tree[r]);
	        }
	    }
	    return ans;
	}
}*val,*root;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n,q;
	cin>>n>>q;
	val=new node(n);
	root=new node(n);
	for (int i=1;i<=n;i++){
		cin>>arr[i];
		while (s.size() && arr[s.top()]<=arr[i]){
			nxt[s.top()]=i;
			s.pop();
		}
		s.emplace(i);
		val->upd(i,arr[i]);
	}
	while (s.size()){
		nxt[s.top()]=n+1;
		s.pop();
	}
	for (int i=1;i<=n;i++){
		if (nxt[i]-1!=i){
			ll ele=val->query(i+1,nxt[i]-1).first;
			root->upd(i,arr[i]+ele);
		}
	}
	ll l,r,x;
	for (int i=1;i<=q;i++){
		cin>>l>>r>>x;
		ll p=val->query(l,r).second;
		cerr<<p<<' ';
		ll ans=0;
		if (l!=p){
			ans=max(ans,root->query(l,p-1).first);
		}
		if (p!=r){
			ans=max(ans,arr[p]+val->query(p+1,r).first);
		}
		cout<<(ans<=x)<<endl;
		cerr<<ans<<endl;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 65112 KB Output is correct
2 Correct 10 ms 65124 KB Output is correct
3 Correct 11 ms 65116 KB Output is correct
4 Correct 10 ms 65088 KB Output is correct
5 Correct 10 ms 65112 KB Output is correct
6 Correct 10 ms 65088 KB Output is correct
7 Correct 11 ms 65116 KB Output is correct
8 Correct 10 ms 65116 KB Output is correct
9 Correct 11 ms 65116 KB Output is correct
10 Correct 10 ms 65116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 65112 KB Output is correct
2 Correct 10 ms 65124 KB Output is correct
3 Correct 11 ms 65116 KB Output is correct
4 Correct 10 ms 65088 KB Output is correct
5 Correct 10 ms 65112 KB Output is correct
6 Correct 10 ms 65088 KB Output is correct
7 Correct 11 ms 65116 KB Output is correct
8 Correct 10 ms 65116 KB Output is correct
9 Correct 11 ms 65116 KB Output is correct
10 Correct 10 ms 65116 KB Output is correct
11 Correct 12 ms 65112 KB Output is correct
12 Correct 12 ms 65116 KB Output is correct
13 Correct 12 ms 65248 KB Output is correct
14 Correct 14 ms 65112 KB Output is correct
15 Correct 14 ms 65116 KB Output is correct
16 Correct 13 ms 65156 KB Output is correct
17 Correct 13 ms 65112 KB Output is correct
18 Correct 12 ms 65116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1285 ms 112324 KB Output is correct
2 Correct 1335 ms 113372 KB Output is correct
3 Correct 1322 ms 113508 KB Output is correct
4 Correct 1316 ms 113708 KB Output is correct
5 Correct 1039 ms 113832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 71700 KB Output is correct
2 Correct 96 ms 71504 KB Output is correct
3 Correct 79 ms 71516 KB Output is correct
4 Correct 77 ms 71392 KB Output is correct
5 Correct 74 ms 71420 KB Output is correct
6 Correct 68 ms 71248 KB Output is correct
7 Correct 68 ms 71248 KB Output is correct
8 Correct 73 ms 71252 KB Output is correct
9 Correct 40 ms 66640 KB Output is correct
10 Correct 74 ms 71248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 65112 KB Output is correct
2 Correct 10 ms 65124 KB Output is correct
3 Correct 11 ms 65116 KB Output is correct
4 Correct 10 ms 65088 KB Output is correct
5 Correct 10 ms 65112 KB Output is correct
6 Correct 10 ms 65088 KB Output is correct
7 Correct 11 ms 65116 KB Output is correct
8 Correct 10 ms 65116 KB Output is correct
9 Correct 11 ms 65116 KB Output is correct
10 Correct 10 ms 65116 KB Output is correct
11 Correct 12 ms 65112 KB Output is correct
12 Correct 12 ms 65116 KB Output is correct
13 Correct 12 ms 65248 KB Output is correct
14 Correct 14 ms 65112 KB Output is correct
15 Correct 14 ms 65116 KB Output is correct
16 Correct 13 ms 65156 KB Output is correct
17 Correct 13 ms 65112 KB Output is correct
18 Correct 12 ms 65116 KB Output is correct
19 Correct 220 ms 76372 KB Output is correct
20 Correct 236 ms 76368 KB Output is correct
21 Correct 191 ms 76020 KB Output is correct
22 Correct 187 ms 76116 KB Output is correct
23 Correct 202 ms 76328 KB Output is correct
24 Correct 148 ms 76116 KB Output is correct
25 Correct 152 ms 75952 KB Output is correct
26 Correct 171 ms 76512 KB Output is correct
27 Correct 166 ms 76304 KB Output is correct
28 Correct 161 ms 76116 KB Output is correct
29 Correct 164 ms 76628 KB Output is correct
30 Correct 210 ms 76368 KB Output is correct
31 Correct 175 ms 76392 KB Output is correct
32 Correct 168 ms 76444 KB Output is correct
33 Correct 160 ms 76368 KB Output is correct
34 Correct 143 ms 75860 KB Output is correct
35 Correct 144 ms 75916 KB Output is correct
36 Correct 139 ms 75800 KB Output is correct
37 Correct 142 ms 75600 KB Output is correct
38 Correct 141 ms 75792 KB Output is correct
39 Correct 160 ms 75264 KB Output is correct
40 Correct 116 ms 74064 KB Output is correct
41 Correct 155 ms 74428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 65112 KB Output is correct
2 Correct 10 ms 65124 KB Output is correct
3 Correct 11 ms 65116 KB Output is correct
4 Correct 10 ms 65088 KB Output is correct
5 Correct 10 ms 65112 KB Output is correct
6 Correct 10 ms 65088 KB Output is correct
7 Correct 11 ms 65116 KB Output is correct
8 Correct 10 ms 65116 KB Output is correct
9 Correct 11 ms 65116 KB Output is correct
10 Correct 10 ms 65116 KB Output is correct
11 Correct 12 ms 65112 KB Output is correct
12 Correct 12 ms 65116 KB Output is correct
13 Correct 12 ms 65248 KB Output is correct
14 Correct 14 ms 65112 KB Output is correct
15 Correct 14 ms 65116 KB Output is correct
16 Correct 13 ms 65156 KB Output is correct
17 Correct 13 ms 65112 KB Output is correct
18 Correct 12 ms 65116 KB Output is correct
19 Correct 1285 ms 112324 KB Output is correct
20 Correct 1335 ms 113372 KB Output is correct
21 Correct 1322 ms 113508 KB Output is correct
22 Correct 1316 ms 113708 KB Output is correct
23 Correct 1039 ms 113832 KB Output is correct
24 Correct 106 ms 71700 KB Output is correct
25 Correct 96 ms 71504 KB Output is correct
26 Correct 79 ms 71516 KB Output is correct
27 Correct 77 ms 71392 KB Output is correct
28 Correct 74 ms 71420 KB Output is correct
29 Correct 68 ms 71248 KB Output is correct
30 Correct 68 ms 71248 KB Output is correct
31 Correct 73 ms 71252 KB Output is correct
32 Correct 40 ms 66640 KB Output is correct
33 Correct 74 ms 71248 KB Output is correct
34 Correct 220 ms 76372 KB Output is correct
35 Correct 236 ms 76368 KB Output is correct
36 Correct 191 ms 76020 KB Output is correct
37 Correct 187 ms 76116 KB Output is correct
38 Correct 202 ms 76328 KB Output is correct
39 Correct 148 ms 76116 KB Output is correct
40 Correct 152 ms 75952 KB Output is correct
41 Correct 171 ms 76512 KB Output is correct
42 Correct 166 ms 76304 KB Output is correct
43 Correct 161 ms 76116 KB Output is correct
44 Correct 164 ms 76628 KB Output is correct
45 Correct 210 ms 76368 KB Output is correct
46 Correct 175 ms 76392 KB Output is correct
47 Correct 168 ms 76444 KB Output is correct
48 Correct 160 ms 76368 KB Output is correct
49 Correct 143 ms 75860 KB Output is correct
50 Correct 144 ms 75916 KB Output is correct
51 Correct 139 ms 75800 KB Output is correct
52 Correct 142 ms 75600 KB Output is correct
53 Correct 141 ms 75792 KB Output is correct
54 Correct 160 ms 75264 KB Output is correct
55 Correct 116 ms 74064 KB Output is correct
56 Correct 155 ms 74428 KB Output is correct
57 Correct 1295 ms 114252 KB Output is correct
58 Correct 1360 ms 114320 KB Output is correct
59 Correct 1239 ms 114196 KB Output is correct
60 Correct 1277 ms 114188 KB Output is correct
61 Correct 1250 ms 114248 KB Output is correct
62 Correct 1244 ms 114428 KB Output is correct
63 Correct 732 ms 112424 KB Output is correct
64 Correct 719 ms 112320 KB Output is correct
65 Correct 1046 ms 114252 KB Output is correct
66 Correct 1020 ms 114804 KB Output is correct
67 Correct 1016 ms 114168 KB Output is correct
68 Correct 994 ms 114408 KB Output is correct
69 Correct 1006 ms 114268 KB Output is correct
70 Correct 1033 ms 114336 KB Output is correct
71 Correct 1039 ms 114120 KB Output is correct
72 Correct 1038 ms 114216 KB Output is correct
73 Correct 661 ms 110932 KB Output is correct
74 Correct 672 ms 111544 KB Output is correct
75 Correct 668 ms 110628 KB Output is correct
76 Correct 668 ms 110704 KB Output is correct
77 Correct 667 ms 110820 KB Output is correct
78 Correct 911 ms 108056 KB Output is correct
79 Correct 645 ms 97872 KB Output is correct
80 Correct 899 ms 105080 KB Output is correct