This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <bitset>
typedef long long ll;
using namespace std;
const int N = 5e3 + 10;
int a[N], l[N];
int ans[N][N];
int main() {
int n, q;
cin >> n >> q;
a[0] = 1e9 + 10;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
l[i] = i - 1;
while (a[i] >= a[l[i]]) {
l[i] = l[l[i]];
}
}
for (int i = 1; i <= n; i++) {
ans[i][i] = 0;
for (int j = i + 1; j <= n; j++) {
ans[i][j] = ans[i][j - 1];
if (l[j] >= i) ans[i][j] = max(ans[i][j], a[l[j]] + a[j]);
}
}
while (q--) {
int l, r, k;
cin >> l >> r >> k;
if (ans[l][r] <= k) cout << "1\n";
else cout << "0\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |