이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int NN = 1e7 + 5;
#define ff first
#define ss second
#define pb push_back
vector <pair <int, int>> v[N];
int a[N], k[N], ans[N], st[NN], jog;
void update (int ind, int l, int r, int pos, int val) {
if (l == r) {
st[ind] = max (st[ind], val);
return;
}
if (pos <= (l + r) / 2) {
update (ind * 2, l, (l + r) / 2, pos, val);
}
else {
update (ind * 2 + 1, (l + r) / 2 + 1, r, pos, val);
}
st[ind] = max (st[ind * 2], st[ind * 2 + 1]);
}
void jogap (int ind, int l, int r, int x, int y) {
if (x > r or l > y) return;
if (x <= l and r <= y) {
jog = max (jog, st[ind]);
return;
}
jogap (ind * 2, l, (l + r) / 2, x, y);
jogap (ind * 2 + 1, (l + r) / 2 + 1, r, x, y);
}
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 <= m; ++i) {
int l, r;
cin >> l >> r >> k[i];
v[r].pb ({l, i});
}
// cout << "sak";
// return 0;
stack <int> s;
for (int i = 1; i <= n; ++i) {
while (!s.empty() and a[s.top()] <= a[i]) s.pop();
if (!s.empty()) {
update (1, 1, n, s.top(), a[i] + a[s.top()]);
}
s.push (i);
for (pair <int, int> x : v[i]) {
// x bilen i aralyk
jog = 0;
jogap (1, 1, n, x.ff, i);
if (k[x.ss] >= jog) {
ans[x.ss] = 1;
}
}
}
for (int i = 1; i <= m; ++i) {
cout << ans[i] << endl;
}
}
# | 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... |