Submission #286901

# Submission time Handle Problem Language Result Execution time Memory
286901 2020-08-31T06:49:03 Z bensonlzl Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1898 ms 100496 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<ll,ll> pi;
typedef pair<pi,ll> pii;

ll N, M, L, R, K;
ll W[1000005], hleft[1000005];
ll ans[1000005];

vector<pii> quer[1000005];

ll seg[4000005];

void update(int s, int e, int node, int x, ll v){
	if (s == e){
		seg[node] = max(seg[node],v);
		return;
	}
	if (x <= (s+e)/2) update(s,(s+e)/2,2*node,x,v);
	else update((s+e)/2+1,e,2*node+1,x,v);
	seg[node] = max(seg[2*node],seg[2*node+1]);
}

ll query(int s, int e, int node, int l, int r){
	if (l > e || r < s) return 0;
	if (l <= s && e <= r) return seg[node];
	return max(query(s,(s+e)/2,2*node,l,r),query((s+e)/2+1,e,2*node+1,l,r));
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> M;
	for (int i = 1; i <= N; ++i){
		cin >> W[i];
	}
	vector<pi> st;
	for (int i = 1; i <= N; ++i){
		while (!st.empty() && st.back().first <= W[i]) st.pop_back();
		if (!st.empty()){
			hleft[i] = st.back().second;
		}
		else{
			hleft[i] = -1;
		}
		st.push_back(pi(W[i],i));
	}
	for (int i = 1; i <= M; ++i){
		cin >> L >> R >> K;
		quer[R].push_back(pii(pi(L,K),i));
	}
	for (int i = 1; i <= N; ++i){
		if (hleft[i] != -1){
			update(1,N,1,hleft[i],W[i] + W[hleft[i]]);
		}
		for (auto it : quer[i]){
			ll x = query(1,N,1,it.first.first,i);
			if (x > it.first.second) ans[it.second] = 0;
			else ans[it.second] = 1;
		}
	}
	for (int i = 1; i <= M; ++i){
		cout << ans[i] << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 17 ms 23936 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 17 ms 23936 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 16 ms 23936 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 17 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 17 ms 23936 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 17 ms 23936 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 16 ms 23936 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 17 ms 23936 KB Output is correct
11 Correct 19 ms 24192 KB Output is correct
12 Correct 20 ms 24320 KB Output is correct
13 Correct 21 ms 24448 KB Output is correct
14 Correct 22 ms 24448 KB Output is correct
15 Correct 21 ms 24448 KB Output is correct
16 Correct 22 ms 24320 KB Output is correct
17 Correct 20 ms 24192 KB Output is correct
18 Correct 20 ms 24192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1851 ms 98288 KB Output is correct
2 Correct 1882 ms 98416 KB Output is correct
3 Correct 1858 ms 98308 KB Output is correct
4 Correct 1876 ms 98496 KB Output is correct
5 Correct 1438 ms 82040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 31736 KB Output is correct
2 Correct 125 ms 33784 KB Output is correct
3 Correct 119 ms 31528 KB Output is correct
4 Correct 119 ms 31480 KB Output is correct
5 Correct 117 ms 31480 KB Output is correct
6 Correct 95 ms 31480 KB Output is correct
7 Correct 99 ms 31480 KB Output is correct
8 Correct 108 ms 31020 KB Output is correct
9 Correct 66 ms 29096 KB Output is correct
10 Correct 108 ms 31016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 17 ms 23936 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 17 ms 23936 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 16 ms 23936 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 17 ms 23936 KB Output is correct
11 Correct 19 ms 24192 KB Output is correct
12 Correct 20 ms 24320 KB Output is correct
13 Correct 21 ms 24448 KB Output is correct
14 Correct 22 ms 24448 KB Output is correct
15 Correct 21 ms 24448 KB Output is correct
16 Correct 22 ms 24320 KB Output is correct
17 Correct 20 ms 24192 KB Output is correct
18 Correct 20 ms 24192 KB Output is correct
19 Correct 318 ms 41376 KB Output is correct
20 Correct 317 ms 41336 KB Output is correct
21 Correct 260 ms 41976 KB Output is correct
22 Correct 260 ms 41976 KB Output is correct
23 Correct 276 ms 41900 KB Output is correct
24 Correct 219 ms 37752 KB Output is correct
25 Correct 219 ms 37752 KB Output is correct
26 Correct 254 ms 37624 KB Output is correct
27 Correct 244 ms 37620 KB Output is correct
28 Correct 267 ms 37496 KB Output is correct
29 Correct 277 ms 37240 KB Output is correct
30 Correct 263 ms 37236 KB Output is correct
31 Correct 264 ms 37240 KB Output is correct
32 Correct 268 ms 37368 KB Output is correct
33 Correct 269 ms 37368 KB Output is correct
34 Correct 197 ms 37240 KB Output is correct
35 Correct 227 ms 37368 KB Output is correct
36 Correct 196 ms 37436 KB Output is correct
37 Correct 195 ms 37496 KB Output is correct
38 Correct 196 ms 37368 KB Output is correct
39 Correct 235 ms 38188 KB Output is correct
40 Correct 174 ms 35232 KB Output is correct
41 Correct 231 ms 36900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 17 ms 23936 KB Output is correct
3 Correct 16 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 17 ms 23936 KB Output is correct
7 Correct 17 ms 23936 KB Output is correct
8 Correct 16 ms 23936 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 17 ms 23936 KB Output is correct
11 Correct 19 ms 24192 KB Output is correct
12 Correct 20 ms 24320 KB Output is correct
13 Correct 21 ms 24448 KB Output is correct
14 Correct 22 ms 24448 KB Output is correct
15 Correct 21 ms 24448 KB Output is correct
16 Correct 22 ms 24320 KB Output is correct
17 Correct 20 ms 24192 KB Output is correct
18 Correct 20 ms 24192 KB Output is correct
19 Correct 1851 ms 98288 KB Output is correct
20 Correct 1882 ms 98416 KB Output is correct
21 Correct 1858 ms 98308 KB Output is correct
22 Correct 1876 ms 98496 KB Output is correct
23 Correct 1438 ms 82040 KB Output is correct
24 Correct 142 ms 31736 KB Output is correct
25 Correct 125 ms 33784 KB Output is correct
26 Correct 119 ms 31528 KB Output is correct
27 Correct 119 ms 31480 KB Output is correct
28 Correct 117 ms 31480 KB Output is correct
29 Correct 95 ms 31480 KB Output is correct
30 Correct 99 ms 31480 KB Output is correct
31 Correct 108 ms 31020 KB Output is correct
32 Correct 66 ms 29096 KB Output is correct
33 Correct 108 ms 31016 KB Output is correct
34 Correct 318 ms 41376 KB Output is correct
35 Correct 317 ms 41336 KB Output is correct
36 Correct 260 ms 41976 KB Output is correct
37 Correct 260 ms 41976 KB Output is correct
38 Correct 276 ms 41900 KB Output is correct
39 Correct 219 ms 37752 KB Output is correct
40 Correct 219 ms 37752 KB Output is correct
41 Correct 254 ms 37624 KB Output is correct
42 Correct 244 ms 37620 KB Output is correct
43 Correct 267 ms 37496 KB Output is correct
44 Correct 277 ms 37240 KB Output is correct
45 Correct 263 ms 37236 KB Output is correct
46 Correct 264 ms 37240 KB Output is correct
47 Correct 268 ms 37368 KB Output is correct
48 Correct 269 ms 37368 KB Output is correct
49 Correct 197 ms 37240 KB Output is correct
50 Correct 227 ms 37368 KB Output is correct
51 Correct 196 ms 37436 KB Output is correct
52 Correct 195 ms 37496 KB Output is correct
53 Correct 196 ms 37368 KB Output is correct
54 Correct 235 ms 38188 KB Output is correct
55 Correct 174 ms 35232 KB Output is correct
56 Correct 231 ms 36900 KB Output is correct
57 Correct 1898 ms 99212 KB Output is correct
58 Correct 1832 ms 99372 KB Output is correct
59 Correct 1748 ms 100496 KB Output is correct
60 Correct 1752 ms 100428 KB Output is correct
61 Correct 1724 ms 100472 KB Output is correct
62 Correct 1786 ms 100216 KB Output is correct
63 Correct 1098 ms 84732 KB Output is correct
64 Correct 1112 ms 84728 KB Output is correct
65 Correct 1415 ms 84132 KB Output is correct
66 Correct 1388 ms 83960 KB Output is correct
67 Correct 1399 ms 83576 KB Output is correct
68 Correct 1444 ms 82296 KB Output is correct
69 Correct 1450 ms 82348 KB Output is correct
70 Correct 1452 ms 82552 KB Output is correct
71 Correct 1452 ms 82620 KB Output is correct
72 Correct 1413 ms 82552 KB Output is correct
73 Correct 962 ms 80336 KB Output is correct
74 Correct 982 ms 80240 KB Output is correct
75 Correct 956 ms 80504 KB Output is correct
76 Correct 968 ms 80248 KB Output is correct
77 Correct 969 ms 80108 KB Output is correct
78 Correct 1259 ms 85656 KB Output is correct
79 Correct 885 ms 70180 KB Output is correct
80 Correct 1231 ms 79112 KB Output is correct