Submission #860179

# Submission time Handle Problem Language Result Execution time Memory
860179 2023-10-12T04:04:58 Z Halym2007 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++11
13 / 100
2388 ms 47208 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int a[N], p[N], cep[N];
int main () {
//	freopen ("input.txt", "r", stdin);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	for (int i = 1; i <= n - 1; ++i) {
		if (a[i] > a[i + 1]) {
			p[i] = 1;
		}
	}
	for (int i = 1; i <= n; ++i) p[i] += p[i - 1];
	
	stack <int> s;
	for (int i = 1; i <= n; ++i) {
		cep[i] = -1;
		while (!s.empty() and a[s.top()] <= a[i]) s.pop();
		if (!s.empty()) {
			cep[i] = s.top();
		}
		s.push(i);
	}
	
	for (int i = 1; i <= m; ++i) {
		int	l, r, k;
		cin >> l >> r >> k;
		if (p[r - 1] - p[l - 1] == 0) {
			cout << "1\n";
			continue;
		}
		bool tr = 0;
		for (int j = l; j <= r; ++j) {
			if (cep[j] != -1) {
				if (a[cep[j]] + a[j] > k) {
					tr = 1;
					break;
				}
			}
		}
		if (tr) cout << "0\n";
		else cout << "1\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2388 ms 13988 KB Output is correct
2 Correct 2177 ms 46952 KB Output is correct
3 Correct 2287 ms 46644 KB Output is correct
4 Correct 2250 ms 47208 KB Output is correct
5 Correct 2204 ms 47124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 722 ms 9088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Halted 0 ms 0 KB -