이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
struct query{
int id,l,r,mood;
};
bool comp(query a, query b){
return a.l>b.l;
}
//BIT Fenwick tree
int n ;
long long bit[200001]={0};
void add(int e,long long v){
while(e<=n){
bit[e] = max(bit[e],v);
e+=e&-e;
}
}
long long sum(int e){
long long res = 0;
while(e>=1){
res=max(res,bit[e]);
e -= e&-e;
}
return res;
}
//end BIT
int main(){
int q;
cin>>n>>q;
int arr[n+1];
for(int i = 1;i<=n;i++)cin>>arr[i];
vector<query> v;
for(int i = 1;i<=q;i++){
query tmp;
cin>>tmp.l>>tmp.r>>tmp.mood;
tmp.id = i;
v.push_back(tmp);
}
sort(v.begin(),v.end(),comp);
int now = n;
stack<int> st;
int ans[q+1];
for(auto qu:v){
while(now>=qu.l){
while(st.size()&&arr[now]>arr[st.top()]){
add(st.top(),arr[st.top()]+arr[now]);
st.pop();
}
while(st.size()&&arr[now]==arr[st.top()])st.pop();
st.push(now);
now--;
}
ans[qu.id] = (sum(qu.r)<=qu.mood);
}
for(int i = 1;i<=q;i++){
cout<<ans[i]<<"\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... |