Submission #1094596

# Submission time Handle Problem Language Result Execution time Memory
1094596 2024-09-30T04:49:52 Z Muhammet Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
185 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

#define sz(s) (int)s.size()

const int N = 1e5+5;

int n, m, l[N], r[N], k[N], p[N], a[N], sp[N][30], b[N][1005];

vector <int> v[1005];

int main(){
	// ios::sync_with_stdio(false); cin.tie(nullptr);
	cin >> n >> m;
	int mx = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		p[i] = p[i-1] + (a[i] < a[i-1]);
		sp[i][0] = a[i];
		mx = max(mx,a[i]);
		v[a[i]].push_back(i);
	}
	for(int i = 1; i <= n; i++){
		b[i][a[i]] = i;
		if(i == v[a[i]].back()){
			for(int j = i; j <= n; j++){
				b[j][a[i]] = i;
			}
			continue;
		}
		int t = *upper_bound(v[a[i]].begin(), v[a[i]].end(), i);
		for(int j = i; j < t; j++){
			b[j][a[i]] = i;
		}
	}
	for(int j = 1; j <= 25; j++){
		for(int i = 1; i <= n-(1<<j)+1; i++){
			sp[i][j] = max(sp[i][j-1],sp[i+(1<<(j-1))][j-1]);
		}
	}
	for(int i = 1; i <= m; i++){
		cin >> l[i] >> r[i] >> k[i];
		int k1 = -1;
		for(int j = 0; j <= mx; j++){
			int ind = b[r[i]][j];
			ind--;
			if(ind < l[i]) continue;
			int lg = log2(ind-l[i]+1);
			int x = max(sp[l[i]][lg], sp[ind-(1<<lg)+1][lg]);
			if(x > j) k1 = max(k1, x-j);
		}
		cout << (k1 <= k[i] and k1 != -1) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 8796 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 185 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -