Submission #964907

# Submission time Handle Problem Language Result Execution time Memory
964907 2024-04-17T17:13:26 Z Acanikolic Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1288 ms 110256 KB
#include <bits/stdc++.h>
		 		
//#define int long long 
		 
#define pb push_back 
		
#define F first
		 
#define S second
		 
using namespace std;
		 
const int N = 1000000 + 10;
		 
const int mod = 1e9 + 7;
		 
const int inf = 1e9; 	

int a[N],res[N];
vector<array<int,3>>kveri[N];

long long st[N * 4];

void update(int node,int tl,int tr,int index,long long val) {
	if(tl > index || tr < index) return;
	if(tl == tr) {
		st[node] = val;
		return;
	}
	int mid = (tl + tr) / 2;
	update(node * 2,tl,mid,index,val);
	update(node * 2 + 1,mid + 1,tr,index,val);
	st[node] = max(st[node * 2],st[node * 2 + 1]);
}

long long get(int node,int tl,int tr,int l,int r) {
	if(tl > r || tr < l) return 0ll;
	if(tl >= l && tr <= r) return st[node];
	int mid = (tl + tr) / 2;
	return max(get(node * 2,tl,mid,l,r),get(node * 2 + 1,mid + 1,tr,l,r));
}
	 		 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	
	int n,q;
	cin >> n >> q;
	vector<int>a(n + 1);
	for(int i = 1; i <= n; i++) cin >> a[i];
	vector<int>prev(n + 1,-1);
	stack<int>st;
	for(int i = 1; i <= n; i++) {
		while(st.size() && a[st.top()] <= a[i]) st.pop();
		if(st.size()) prev[i] = st.top();
		st.push(i);
	}
	for(int i = 1; i <= q; i++) {
		int l,r,k;
		cin >> l >> r >> k;
		kveri[r].pb({l,k,i});
	}
	for(int i = 1; i <= n; i++) {
		if(prev[i] != -1) update(1,1,n,prev[i],a[prev[i]] + a[i]);
		for(auto X : kveri[i]) {
			res[X[2]] = (get(1,1,n,X[0],i) > X[1] ? 0 : 1);
		}
	}
	for(int i = 1; i <= q; i++) cout << res[i] << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25176 KB Output is correct
2 Correct 5 ms 24924 KB Output is correct
3 Correct 6 ms 24924 KB Output is correct
4 Correct 6 ms 25088 KB Output is correct
5 Correct 6 ms 24924 KB Output is correct
6 Correct 6 ms 25108 KB Output is correct
7 Correct 6 ms 24924 KB Output is correct
8 Correct 7 ms 24924 KB Output is correct
9 Correct 6 ms 24920 KB Output is correct
10 Correct 7 ms 24920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25176 KB Output is correct
2 Correct 5 ms 24924 KB Output is correct
3 Correct 6 ms 24924 KB Output is correct
4 Correct 6 ms 25088 KB Output is correct
5 Correct 6 ms 24924 KB Output is correct
6 Correct 6 ms 25108 KB Output is correct
7 Correct 6 ms 24924 KB Output is correct
8 Correct 7 ms 24924 KB Output is correct
9 Correct 6 ms 24920 KB Output is correct
10 Correct 7 ms 24920 KB Output is correct
11 Correct 8 ms 25096 KB Output is correct
12 Correct 8 ms 25176 KB Output is correct
13 Correct 9 ms 25216 KB Output is correct
14 Correct 9 ms 25436 KB Output is correct
15 Correct 9 ms 25272 KB Output is correct
16 Correct 9 ms 25412 KB Output is correct
17 Correct 8 ms 25184 KB Output is correct
18 Correct 8 ms 25176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1260 ms 77008 KB Output is correct
2 Correct 1288 ms 77104 KB Output is correct
3 Correct 1177 ms 77112 KB Output is correct
4 Correct 1225 ms 77324 KB Output is correct
5 Correct 1018 ms 60524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 30208 KB Output is correct
2 Correct 77 ms 31896 KB Output is correct
3 Correct 75 ms 30032 KB Output is correct
4 Correct 86 ms 30028 KB Output is correct
5 Correct 73 ms 30044 KB Output is correct
6 Correct 58 ms 31480 KB Output is correct
7 Correct 56 ms 31452 KB Output is correct
8 Correct 70 ms 29792 KB Output is correct
9 Correct 35 ms 28084 KB Output is correct
10 Correct 64 ms 29752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25176 KB Output is correct
2 Correct 5 ms 24924 KB Output is correct
3 Correct 6 ms 24924 KB Output is correct
4 Correct 6 ms 25088 KB Output is correct
5 Correct 6 ms 24924 KB Output is correct
6 Correct 6 ms 25108 KB Output is correct
7 Correct 6 ms 24924 KB Output is correct
8 Correct 7 ms 24924 KB Output is correct
9 Correct 6 ms 24920 KB Output is correct
10 Correct 7 ms 24920 KB Output is correct
11 Correct 8 ms 25096 KB Output is correct
12 Correct 8 ms 25176 KB Output is correct
13 Correct 9 ms 25216 KB Output is correct
14 Correct 9 ms 25436 KB Output is correct
15 Correct 9 ms 25272 KB Output is correct
16 Correct 9 ms 25412 KB Output is correct
17 Correct 8 ms 25184 KB Output is correct
18 Correct 8 ms 25176 KB Output is correct
19 Correct 198 ms 41812 KB Output is correct
20 Correct 198 ms 41812 KB Output is correct
21 Correct 167 ms 41592 KB Output is correct
22 Correct 200 ms 41364 KB Output is correct
23 Correct 175 ms 41364 KB Output is correct
24 Correct 129 ms 36892 KB Output is correct
25 Correct 131 ms 36952 KB Output is correct
26 Correct 178 ms 37200 KB Output is correct
27 Correct 138 ms 37300 KB Output is correct
28 Correct 149 ms 37380 KB Output is correct
29 Correct 153 ms 37712 KB Output is correct
30 Correct 164 ms 37880 KB Output is correct
31 Correct 155 ms 37716 KB Output is correct
32 Correct 156 ms 37732 KB Output is correct
33 Correct 158 ms 37840 KB Output is correct
34 Correct 119 ms 38484 KB Output is correct
35 Correct 117 ms 38564 KB Output is correct
36 Correct 115 ms 38400 KB Output is correct
37 Correct 114 ms 38392 KB Output is correct
38 Correct 134 ms 38516 KB Output is correct
39 Correct 140 ms 37492 KB Output is correct
40 Correct 115 ms 34436 KB Output is correct
41 Correct 142 ms 35960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 25176 KB Output is correct
2 Correct 5 ms 24924 KB Output is correct
3 Correct 6 ms 24924 KB Output is correct
4 Correct 6 ms 25088 KB Output is correct
5 Correct 6 ms 24924 KB Output is correct
6 Correct 6 ms 25108 KB Output is correct
7 Correct 6 ms 24924 KB Output is correct
8 Correct 7 ms 24924 KB Output is correct
9 Correct 6 ms 24920 KB Output is correct
10 Correct 7 ms 24920 KB Output is correct
11 Correct 8 ms 25096 KB Output is correct
12 Correct 8 ms 25176 KB Output is correct
13 Correct 9 ms 25216 KB Output is correct
14 Correct 9 ms 25436 KB Output is correct
15 Correct 9 ms 25272 KB Output is correct
16 Correct 9 ms 25412 KB Output is correct
17 Correct 8 ms 25184 KB Output is correct
18 Correct 8 ms 25176 KB Output is correct
19 Correct 1260 ms 77008 KB Output is correct
20 Correct 1288 ms 77104 KB Output is correct
21 Correct 1177 ms 77112 KB Output is correct
22 Correct 1225 ms 77324 KB Output is correct
23 Correct 1018 ms 60524 KB Output is correct
24 Correct 102 ms 30208 KB Output is correct
25 Correct 77 ms 31896 KB Output is correct
26 Correct 75 ms 30032 KB Output is correct
27 Correct 86 ms 30028 KB Output is correct
28 Correct 73 ms 30044 KB Output is correct
29 Correct 58 ms 31480 KB Output is correct
30 Correct 56 ms 31452 KB Output is correct
31 Correct 70 ms 29792 KB Output is correct
32 Correct 35 ms 28084 KB Output is correct
33 Correct 64 ms 29752 KB Output is correct
34 Correct 198 ms 41812 KB Output is correct
35 Correct 198 ms 41812 KB Output is correct
36 Correct 167 ms 41592 KB Output is correct
37 Correct 200 ms 41364 KB Output is correct
38 Correct 175 ms 41364 KB Output is correct
39 Correct 129 ms 36892 KB Output is correct
40 Correct 131 ms 36952 KB Output is correct
41 Correct 178 ms 37200 KB Output is correct
42 Correct 138 ms 37300 KB Output is correct
43 Correct 149 ms 37380 KB Output is correct
44 Correct 153 ms 37712 KB Output is correct
45 Correct 164 ms 37880 KB Output is correct
46 Correct 155 ms 37716 KB Output is correct
47 Correct 156 ms 37732 KB Output is correct
48 Correct 158 ms 37840 KB Output is correct
49 Correct 119 ms 38484 KB Output is correct
50 Correct 117 ms 38564 KB Output is correct
51 Correct 115 ms 38400 KB Output is correct
52 Correct 114 ms 38392 KB Output is correct
53 Correct 134 ms 38516 KB Output is correct
54 Correct 140 ms 37492 KB Output is correct
55 Correct 115 ms 34436 KB Output is correct
56 Correct 142 ms 35960 KB Output is correct
57 Correct 1219 ms 110256 KB Output is correct
58 Correct 1232 ms 109888 KB Output is correct
59 Correct 1060 ms 108672 KB Output is correct
60 Correct 1148 ms 108512 KB Output is correct
61 Correct 1092 ms 108620 KB Output is correct
62 Correct 1131 ms 108608 KB Output is correct
63 Correct 651 ms 89024 KB Output is correct
64 Correct 637 ms 88816 KB Output is correct
65 Correct 914 ms 91708 KB Output is correct
66 Correct 875 ms 92068 KB Output is correct
67 Correct 827 ms 92224 KB Output is correct
68 Correct 971 ms 93656 KB Output is correct
69 Correct 976 ms 93724 KB Output is correct
70 Correct 912 ms 93424 KB Output is correct
71 Correct 935 ms 93100 KB Output is correct
72 Correct 968 ms 93344 KB Output is correct
73 Correct 579 ms 90924 KB Output is correct
74 Correct 588 ms 92012 KB Output is correct
75 Correct 592 ms 91056 KB Output is correct
76 Correct 600 ms 91192 KB Output is correct
77 Correct 567 ms 90560 KB Output is correct
78 Correct 919 ms 92168 KB Output is correct
79 Correct 652 ms 75044 KB Output is correct
80 Correct 796 ms 83608 KB Output is correct