답안 #1096218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096218 2024-10-04T06:06:40 Z Muhammet Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
3000 ms 51300 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;
		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]);
		}
		ll ind = id[l]+1;
		while(ind < id[r]){
			ans = max(ans,an[ind]);
			mx = max(mx,mmx[ind]);
			ind++;
		}
		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]);
				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]);
			}
		}
		cout << (ans > k ? 0 : 1) << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3025 ms 51300 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 193 ms 6228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -