Submission #1096194

# Submission time Handle Problem Language Result Execution time Memory
1096194 2024-10-04T05:06:44 Z Muhammet Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
201 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

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

const int N = 1e6+5;

int n, m, l[N], r[N], a[N], id[N], an[N], mmx[N];

pair <int,int> rn[N];

int main(){
	ios::sync_with_stdio (false); cin.tie(nullptr);
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	int nq = sqrt(n), cnt = 0;
	vector <vector <int>> b(nq+10, vector <int> (n+10,0));
	for(int i = 1; i <= n; i++){
		cnt++;
		int 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;
		}
		mmx[cnt] = mx;
		rn[cnt] = {i,min(i+nq-1,n)};
		i = min(i+nq-1,n);
	}
	vector <int> v;
	for(int i = 1; i <= n; i++){
		v.clear();
		for(int j = i; j <= min(i+nq-1,n); j++){
			v.push_back(a[j]);
		}
		sort(v.begin(), v.end());
		int ind = 0;
		int mx = 0;
		for(int j = i-1; j >= 1; j--){
			mx = max(mx,a[j]);
			while(ind < sz(v)-1 and v[ind+1] < mx) ind++;
			b[id[i]][j] = v[ind];
		}
		i = min(i+nq-1,n);
	}
	for(int i = 1; i <= m; i++){
		int l, r, k;
		cin >> l >> r >> k;
		int 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]);
		}
		int ind = id[l]+1;
		while(ind < id[r]){
			ans = max(ans,an[ind]);
			if(b[ind][l] < mx) ans = max(ans,mx+b[ind][l]);
			mx = max(mx,mmx[ind]);
			ind++;
		}
		cout << (ans > k ? 0 : 1) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Incorrect 1 ms 6492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Incorrect 1 ms 6492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 188 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 201 ms 134860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Incorrect 1 ms 6492 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6744 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Incorrect 1 ms 6492 KB Output isn't correct
4 Halted 0 ms 0 KB -