이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct query{
int l,r,id,val;
};
int n,m,a[1000005],ans[100005],cnt,pt,seg[4000005];
stack <int> s;
pair <int,int> inv[1000005];
query q[1000005];
bool cmp(query a1,query a2){
if (a1.r == a2.r) return a1.id < a2.id;
return a1.l > a2.l;
}
bool invcmp(pair<int,int> a1,pair<int,int> a2){
if (a1.first == a2.first) return a1.second > a2.second;
return a1.first > a2.first;
}
void update(int id,int l,int r,int pos,int v){
if (l == r)
seg[id]=max(seg[id],v);
else
{
int mid=(l+r)/2;
if (pos <= mid)update(id*2,l,mid,pos,v);
else update(id*2+1,mid+1,r,pos,v);
seg[id]=max(seg[id*2],seg[id*2+1]);
}
}
int getans(int id,int l,int r,int x,int y){
if (x <= l && r <= y)
return seg[id];
if (x > r || y < l)
return -1;
int mid=(l+r)/2;
return max(getans(id*2,l,mid,x,y),getans(id*2+1,mid+1,r,x,y));
}
int main(){
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i=1;i<=n;i++){
cin >> a[i];
while (!s.empty() && a[i] >= a[s.top()]) s.pop();
if (!s.empty()) inv[++cnt]=make_pair(s.top(),i);
s.push(i);
}
for (int i=1;i<=m;i++){
cin >> q[i].l >> q[i].r >> q[i].val;
q[i].id=i;
}
sort(inv+1,inv+1+cnt,invcmp); sort(q+1,q+1+m,cmp);
for (int i=1;i<=m;i++){
while (pt < cnt && inv[pt+1].first >= q[i].l) {
pt++;
update(1,1,n,inv[pt].second,a[inv[pt].first]+a[inv[pt].second]);
}
if (getans(1,1,n,q[i].l,q[i].r) <= q[i].val) ans[q[i].id]=1;
}
for (int i=1;i<=m;i++){
cout << ans[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... |