답안 #1096222

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096222 2024-10-04T06:16:43 Z Muhammet Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 74576 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]);
			}
		}
		cout << (ans > k ? 0 : 1) << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 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 0 ms 348 KB Output is correct
7 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 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 0 ms 348 KB Output is correct
7 Correct 0 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 1 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 443 ms 73632 KB Output is correct
2 Correct 427 ms 74516 KB Output is correct
3 Correct 424 ms 74400 KB Output is correct
4 Correct 421 ms 74576 KB Output is correct
5 Execution timed out 3042 ms 63760 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 7028 KB Output is correct
2 Correct 102 ms 6936 KB Output is correct
3 Correct 148 ms 6992 KB Output is correct
4 Correct 123 ms 6996 KB Output is correct
5 Correct 114 ms 6996 KB Output is correct
6 Correct 143 ms 6740 KB Output is correct
7 Correct 142 ms 6664 KB Output is correct
8 Correct 125 ms 6556 KB Output is correct
9 Correct 27 ms 1956 KB Output is correct
10 Correct 152 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 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 0 ms 348 KB Output is correct
7 Correct 0 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 1 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 152 ms 15444 KB Output is correct
20 Correct 150 ms 15440 KB Output is correct
21 Correct 281 ms 15184 KB Output is correct
22 Correct 257 ms 15180 KB Output is correct
23 Correct 253 ms 15184 KB Output is correct
24 Correct 728 ms 15064 KB Output is correct
25 Correct 803 ms 15184 KB Output is correct
26 Correct 593 ms 15428 KB Output is correct
27 Correct 628 ms 15180 KB Output is correct
28 Correct 514 ms 15184 KB Output is correct
29 Correct 304 ms 15444 KB Output is correct
30 Correct 318 ms 15308 KB Output is correct
31 Correct 328 ms 15440 KB Output is correct
32 Correct 355 ms 15276 KB Output is correct
33 Correct 342 ms 15444 KB Output is correct
34 Correct 575 ms 14932 KB Output is correct
35 Correct 577 ms 14928 KB Output is correct
36 Correct 598 ms 14916 KB Output is correct
37 Correct 550 ms 14932 KB Output is correct
38 Correct 566 ms 14928 KB Output is correct
39 Correct 399 ms 13904 KB Output is correct
40 Correct 394 ms 10708 KB Output is correct
41 Correct 367 ms 13396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 456 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 0 ms 348 KB Output is correct
7 Correct 0 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 1 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 5 ms 724 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 3 ms 604 KB Output is correct
19 Correct 443 ms 73632 KB Output is correct
20 Correct 427 ms 74516 KB Output is correct
21 Correct 424 ms 74400 KB Output is correct
22 Correct 421 ms 74576 KB Output is correct
23 Execution timed out 3042 ms 63760 KB Time limit exceeded
24 Halted 0 ms 0 KB -