Submission #236644

# Submission time Handle Problem Language Result Execution time Memory
236644 2020-06-02T17:03:10 Z kshitij_sodani Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1617 ms 75120 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
int n;
int it[1000001];
int aa,bb,cc;
int tree[4000001];
int le[1000001];
int ans[1000001];
vector<pair<pair<int,int>,int>> qq[1000001];
void update(int no,int l,int r,int aa,int val){
	if(l==r){
		tree[no]=val;
	}
	else{
		int mid=(l+r)/2;
		if(aa<=mid){
			update(no*2+1,l,mid,aa,val);
		}
		else{
			update(no*2+2,mid+1,r,aa,val);
		}
		tree[no]=max(tree[no*2+1],tree[no*2+2]);
	}
}
int query(int no,int l,int r,int aa,int bb){
	if(r<aa or l>bb){
		return 0;
	}
	if(aa<=l and r<=bb){
		return tree[no];
	}
	else{
		int mid=(l+r)/2;
		return max(query(no*2+1,l,mid,aa,bb),query(no*2+2,mid+1,r,aa,bb));
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int m;
	cin>>n>>m;
	stack<int> ss;
	memset(le,0,sizeof(le));

	for(int i=0;i<n;i++){
		cin>>it[i];
		while(ss.size()){
			if(it[ss.top()-1]<=it[i]){
				ss.pop();
			}
			else{
				break;
			}
		}
		if(ss.size()){
			le[i]=ss.top();
		}
		ss.push(i+1);
	}
	for(int i=0;i<m;i++){
		ans[i]=0;
		cin>>aa>>bb>>cc;
		aa-=1;
		bb-=1;
		qq[bb].pb({{aa,cc},i});
	}
	for(int i=0;i<n;i++){
		if(le[i]){
			update(0,0,n-1,le[i]-1,it[le[i]-1]+it[i]);
//			cout<<i<<",,"<<le[i]<<endl;
		}
		for(auto j:qq[i]){
	//		cout<<query(0,0,n-1,j.a.a,i)<<","<<j.b<<endl;
			ans[j.b]=(query(0,0,n-1,j.a.a,i)<=j.a.b?1:0);
		}
	}
	for(int i=0;i<m;i++){
		cout<<ans[i]<<'\n';
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 27776 KB Output is correct
2 Correct 19 ms 27776 KB Output is correct
3 Correct 21 ms 27776 KB Output is correct
4 Correct 21 ms 27776 KB Output is correct
5 Correct 19 ms 27776 KB Output is correct
6 Correct 19 ms 27776 KB Output is correct
7 Correct 19 ms 27776 KB Output is correct
8 Correct 21 ms 27776 KB Output is correct
9 Correct 19 ms 27776 KB Output is correct
10 Correct 21 ms 27776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 27776 KB Output is correct
2 Correct 19 ms 27776 KB Output is correct
3 Correct 21 ms 27776 KB Output is correct
4 Correct 21 ms 27776 KB Output is correct
5 Correct 19 ms 27776 KB Output is correct
6 Correct 19 ms 27776 KB Output is correct
7 Correct 19 ms 27776 KB Output is correct
8 Correct 21 ms 27776 KB Output is correct
9 Correct 19 ms 27776 KB Output is correct
10 Correct 21 ms 27776 KB Output is correct
11 Correct 21 ms 27904 KB Output is correct
12 Correct 22 ms 27904 KB Output is correct
13 Correct 23 ms 27904 KB Output is correct
14 Correct 30 ms 28024 KB Output is correct
15 Correct 26 ms 28032 KB Output is correct
16 Correct 23 ms 27904 KB Output is correct
17 Correct 23 ms 27904 KB Output is correct
18 Correct 22 ms 27904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1597 ms 67596 KB Output is correct
2 Correct 1575 ms 67576 KB Output is correct
3 Correct 1556 ms 67496 KB Output is correct
4 Correct 1579 ms 67680 KB Output is correct
5 Correct 1314 ms 59384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 31864 KB Output is correct
2 Correct 116 ms 31608 KB Output is correct
3 Correct 105 ms 30712 KB Output is correct
4 Correct 105 ms 30840 KB Output is correct
5 Correct 108 ms 30832 KB Output is correct
6 Correct 97 ms 30456 KB Output is correct
7 Correct 92 ms 30456 KB Output is correct
8 Correct 107 ms 30772 KB Output is correct
9 Correct 64 ms 29744 KB Output is correct
10 Correct 102 ms 30900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 27776 KB Output is correct
2 Correct 19 ms 27776 KB Output is correct
3 Correct 21 ms 27776 KB Output is correct
4 Correct 21 ms 27776 KB Output is correct
5 Correct 19 ms 27776 KB Output is correct
6 Correct 19 ms 27776 KB Output is correct
7 Correct 19 ms 27776 KB Output is correct
8 Correct 21 ms 27776 KB Output is correct
9 Correct 19 ms 27776 KB Output is correct
10 Correct 21 ms 27776 KB Output is correct
11 Correct 21 ms 27904 KB Output is correct
12 Correct 22 ms 27904 KB Output is correct
13 Correct 23 ms 27904 KB Output is correct
14 Correct 30 ms 28024 KB Output is correct
15 Correct 26 ms 28032 KB Output is correct
16 Correct 23 ms 27904 KB Output is correct
17 Correct 23 ms 27904 KB Output is correct
18 Correct 22 ms 27904 KB Output is correct
19 Correct 271 ms 36088 KB Output is correct
20 Correct 293 ms 36136 KB Output is correct
21 Correct 239 ms 35576 KB Output is correct
22 Correct 249 ms 35576 KB Output is correct
23 Correct 243 ms 35576 KB Output is correct
24 Correct 205 ms 33400 KB Output is correct
25 Correct 207 ms 33400 KB Output is correct
26 Correct 232 ms 33784 KB Output is correct
27 Correct 217 ms 33656 KB Output is correct
28 Correct 229 ms 33656 KB Output is correct
29 Correct 253 ms 34040 KB Output is correct
30 Correct 254 ms 33948 KB Output is correct
31 Correct 239 ms 33912 KB Output is correct
32 Correct 234 ms 33912 KB Output is correct
33 Correct 241 ms 34040 KB Output is correct
34 Correct 190 ms 33112 KB Output is correct
35 Correct 201 ms 33016 KB Output is correct
36 Correct 191 ms 33016 KB Output is correct
37 Correct 191 ms 33272 KB Output is correct
38 Correct 198 ms 33144 KB Output is correct
39 Correct 207 ms 34352 KB Output is correct
40 Correct 169 ms 33068 KB Output is correct
41 Correct 199 ms 33840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 27776 KB Output is correct
2 Correct 19 ms 27776 KB Output is correct
3 Correct 21 ms 27776 KB Output is correct
4 Correct 21 ms 27776 KB Output is correct
5 Correct 19 ms 27776 KB Output is correct
6 Correct 19 ms 27776 KB Output is correct
7 Correct 19 ms 27776 KB Output is correct
8 Correct 21 ms 27776 KB Output is correct
9 Correct 19 ms 27776 KB Output is correct
10 Correct 21 ms 27776 KB Output is correct
11 Correct 21 ms 27904 KB Output is correct
12 Correct 22 ms 27904 KB Output is correct
13 Correct 23 ms 27904 KB Output is correct
14 Correct 30 ms 28024 KB Output is correct
15 Correct 26 ms 28032 KB Output is correct
16 Correct 23 ms 27904 KB Output is correct
17 Correct 23 ms 27904 KB Output is correct
18 Correct 22 ms 27904 KB Output is correct
19 Correct 1597 ms 67596 KB Output is correct
20 Correct 1575 ms 67576 KB Output is correct
21 Correct 1556 ms 67496 KB Output is correct
22 Correct 1579 ms 67680 KB Output is correct
23 Correct 1314 ms 59384 KB Output is correct
24 Correct 122 ms 31864 KB Output is correct
25 Correct 116 ms 31608 KB Output is correct
26 Correct 105 ms 30712 KB Output is correct
27 Correct 105 ms 30840 KB Output is correct
28 Correct 108 ms 30832 KB Output is correct
29 Correct 97 ms 30456 KB Output is correct
30 Correct 92 ms 30456 KB Output is correct
31 Correct 107 ms 30772 KB Output is correct
32 Correct 64 ms 29744 KB Output is correct
33 Correct 102 ms 30900 KB Output is correct
34 Correct 271 ms 36088 KB Output is correct
35 Correct 293 ms 36136 KB Output is correct
36 Correct 239 ms 35576 KB Output is correct
37 Correct 249 ms 35576 KB Output is correct
38 Correct 243 ms 35576 KB Output is correct
39 Correct 205 ms 33400 KB Output is correct
40 Correct 207 ms 33400 KB Output is correct
41 Correct 232 ms 33784 KB Output is correct
42 Correct 217 ms 33656 KB Output is correct
43 Correct 229 ms 33656 KB Output is correct
44 Correct 253 ms 34040 KB Output is correct
45 Correct 254 ms 33948 KB Output is correct
46 Correct 239 ms 33912 KB Output is correct
47 Correct 234 ms 33912 KB Output is correct
48 Correct 241 ms 34040 KB Output is correct
49 Correct 190 ms 33112 KB Output is correct
50 Correct 201 ms 33016 KB Output is correct
51 Correct 191 ms 33016 KB Output is correct
52 Correct 191 ms 33272 KB Output is correct
53 Correct 198 ms 33144 KB Output is correct
54 Correct 207 ms 34352 KB Output is correct
55 Correct 169 ms 33068 KB Output is correct
56 Correct 199 ms 33840 KB Output is correct
57 Correct 1593 ms 75064 KB Output is correct
58 Correct 1617 ms 75120 KB Output is correct
59 Correct 1576 ms 73488 KB Output is correct
60 Correct 1594 ms 73428 KB Output is correct
61 Correct 1584 ms 73508 KB Output is correct
62 Correct 1492 ms 73508 KB Output is correct
63 Correct 995 ms 62976 KB Output is correct
64 Correct 1040 ms 62856 KB Output is correct
65 Correct 1291 ms 65236 KB Output is correct
66 Correct 1313 ms 65216 KB Output is correct
67 Correct 1387 ms 65164 KB Output is correct
68 Correct 1322 ms 66808 KB Output is correct
69 Correct 1315 ms 66696 KB Output is correct
70 Correct 1325 ms 66512 KB Output is correct
71 Correct 1314 ms 66500 KB Output is correct
72 Correct 1322 ms 66404 KB Output is correct
73 Correct 947 ms 63312 KB Output is correct
74 Correct 948 ms 54192 KB Output is correct
75 Correct 937 ms 63140 KB Output is correct
76 Correct 940 ms 60684 KB Output is correct
77 Correct 932 ms 60380 KB Output is correct
78 Correct 1182 ms 67000 KB Output is correct
79 Correct 895 ms 65392 KB Output is correct
80 Correct 1141 ms 63964 KB Output is correct