Submission #1096223

# Submission time Handle Problem Language Result Execution time Memory
1096223 2024-10-04T06:17:34 Z Muhammet Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 58704 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(s) (int)s.size()
#define ff first
#define ss second
#define ll long long

ll n, m;

int main(){
	ios::sync_with_stdio (false); cin.tie(nullptr);
	cin >> n >> m;
	ll nq = sqrt(n), cnt = 0;
	vector <ll> a(n+1), id(n+1), an(nq+10), mmx(nq+10);
	vector <pair<ll,ll>> rn(n+1);
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	vector <ll> v[nq+10];
	for(int i = 1; i <= n; i++){
		cnt++;
		ll mx = 0;
		for(int j = i; j <= min(i+nq-1,n); j++){
			if(mx > a[j]) an[cnt] = max(an[cnt],mx+a[j]);
			mx = max(mx,a[j]);
			id[j] = cnt;
			v[cnt].push_back(a[j]);
		}
		sort(v[cnt].begin(), v[cnt].end());
		mmx[cnt] = mx;
		rn[cnt] = {i,min(i+nq-1,n)};
		i = min(i+nq-1,n);
	}
	for(int i = 1; i <= m; i++){
		ll l, r, k;
		cin >> l >> r >> k;
		ll mx = 0, ans = 0;
		bool tr = 0;
		for(int j = l; j <= min(rn[id[l]].ss,r); j++){
			if(a[j] < mx) ans = max(ans,a[j]+mx);
			mx = max(mx,a[j]);
			if(ans > k){
				tr = 1;
				break;
			}
		}
		if(tr == 1){
			cout << 0 << '\n';
			continue;
		}
		ll ind = id[l]+1;
		while(ind < id[r]){
			ans = max(ans,an[ind]);
			int t = lower_bound(v[ind].begin(), v[ind].end(), mx) - v[ind].begin();
			if(t != 0) ans = max(ans,mx+v[ind][t-1]);
			mx = max(mx,mmx[ind]);
			ind++;
			if(ans > k){
				tr = 1;
				break;
			}
		}
		if(tr == 1){
			cout << 0 << '\n';
			continue;
		}
		if(id[l] != id[r]){
			for(int j = rn[id[r]].ff; j <= r; j++){
				if(a[j] < mx) ans = max(ans,mx+a[j]);
				mx = max(mx,a[j]);
				if(ans > k){
					tr = 1;
					break;
				}
			}
		}
		cout << (ans > k ? 0 : 1) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 3 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 415 ms 57944 KB Output is correct
2 Correct 415 ms 58704 KB Output is correct
3 Correct 450 ms 58260 KB Output is correct
4 Correct 409 ms 58576 KB Output is correct
5 Execution timed out 3097 ms 52816 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 6228 KB Output is correct
2 Correct 106 ms 6196 KB Output is correct
3 Correct 165 ms 6196 KB Output is correct
4 Correct 120 ms 6100 KB Output is correct
5 Correct 107 ms 6344 KB Output is correct
6 Correct 141 ms 6224 KB Output is correct
7 Correct 137 ms 6236 KB Output is correct
8 Correct 128 ms 5968 KB Output is correct
9 Correct 26 ms 1624 KB Output is correct
10 Correct 148 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 3 ms 764 KB Output is correct
19 Correct 147 ms 12368 KB Output is correct
20 Correct 151 ms 12300 KB Output is correct
21 Correct 260 ms 12500 KB Output is correct
22 Correct 274 ms 12464 KB Output is correct
23 Correct 267 ms 12368 KB Output is correct
24 Correct 739 ms 12108 KB Output is correct
25 Correct 750 ms 12152 KB Output is correct
26 Correct 588 ms 12484 KB Output is correct
27 Correct 615 ms 12368 KB Output is correct
28 Correct 521 ms 12308 KB Output is correct
29 Correct 299 ms 12408 KB Output is correct
30 Correct 315 ms 12624 KB Output is correct
31 Correct 321 ms 12480 KB Output is correct
32 Correct 325 ms 12468 KB Output is correct
33 Correct 338 ms 12476 KB Output is correct
34 Correct 611 ms 12116 KB Output is correct
35 Correct 574 ms 12116 KB Output is correct
36 Correct 578 ms 12120 KB Output is correct
37 Correct 576 ms 12184 KB Output is correct
38 Correct 620 ms 12160 KB Output is correct
39 Correct 402 ms 11600 KB Output is correct
40 Correct 389 ms 9108 KB Output is correct
41 Correct 359 ms 11344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 3 ms 604 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 3 ms 728 KB Output is correct
18 Correct 3 ms 764 KB Output is correct
19 Correct 415 ms 57944 KB Output is correct
20 Correct 415 ms 58704 KB Output is correct
21 Correct 450 ms 58260 KB Output is correct
22 Correct 409 ms 58576 KB Output is correct
23 Execution timed out 3097 ms 52816 KB Time limit exceeded
24 Halted 0 ms 0 KB -