이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define N 1000005
struct ii{
int l, r, idx;
bool operator < (ii& o){
return l < o.l;
}
};
struct fw{
int n;
vector<int> bit;
fw(int siz){
n = siz;
bit.resize(n + 1, 0);
}
void ud(int pos, int val){
while (pos <= n){
bit[pos] = max(bit[pos], val);
pos += (pos & (-pos));
}
}
int get(int pos){
int rt = 0;
while (pos >= 1){
rt = max(rt, bit[pos]);
pos -= (pos & (-pos));
}
return rt;
}
};
int n, m, a[N], res[N];
vector<ii> vd, qr[N];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
stack<int> st;
cin >> n >> m;
for (int i = 1; i <= n; i++){
cin >> a[i];
while (st.size() && a[st.top()] <= a[i]) st.pop();
if (st.size()){
vd.push_back({st.top(), i, 0});
}
st.push(i);
}
for (int i = 1; i <= m; i++){
int l, r, k;
cin >> l >> r >> k;
qr[l].push_back({k, r, i});
}
sort(vd.begin(), vd.end());
int j = (int) vd.size();
fw s1(n);
for (int i = n; i >= 1; i--){
while (j - 1 >= 0 && vd[j - 1].l >= i){
j--;
s1.ud(vd[j].r, a[vd[j].l] + a[vd[j].r]);
}
for (auto x : qr[i]){
res[x.idx] = (s1.get(x.r) <= x.l);
}
}
for (int i = 1; i <= m; i++) cout << res[i] << "\n";
return 0;
}
# | 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... |