이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//雪花飄飄北風嘯嘯
//天地一片蒼茫
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl
#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,q;
int arr[1000005];
const int INF=2e9;
struct node{
int s,e,m;
int val,lazy=0;
node *l,*r;
node (int _s,int _e){
s=_s,e=_e,m=s+e>>1;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
val=max(l->val,r->val);
}
else{
val=arr[s]-INF;
}
}
void propo(){
if (lazy){
val+=lazy;
if (s!=e){
l->lazy+=lazy;
r->lazy+=lazy;
}
lazy=0;
}
}
void update(int i,int j,int k){
if (s==i && e==j) lazy+=k;
else{
if (j<=m) l->update(i,j,k);
else if (m<i) r->update(i,j,k);
else l->update(i,m,k),r->update(m+1,j,k);
l->propo(),r->propo();
val=max(l->val,r->val);
}
}
int query(int i,int j){
propo();
if (s==i && e==j) return val;
else if (j<=m) return l->query(i,j);
else if (m<i) return r->query(i,j);
else return max(l->query(i,m),r->query(m+1,j));
}
} *root;
priority_queue<ii,vector<ii>,greater<ii> > pq; //check which nodes can remove INF
struct Q{
int l,r;
int lim;
int idx;
Q(int a,int b,int c,int d){
l=a,r=b,lim=c,idx=d;
}
};
vector<Q> queries;
int ans[1000005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.exceptions(ios::badbit | ios::failbit);
cin>>n>>q;
rep(x,0,n) cin>>arr[x];
root=new node(0,n+5); //hm
int a,b,c;
rep(x,0,q){
cin>>a>>b>>c;
queries.push_back(Q(a-1,b-1,c,x));
}
sort(all(queries),[](Q &i,Q &j){
return i.l>j.l;
});
int curr=n;
vector<int> stk={n};
for (auto &it:queries){
while (curr!=it.l){
curr--;
while (stk.back()!=n && arr[stk.back()]<=arr[curr]){
int temp=stk.back();
stk.pop_back();
root->update(temp,stk.back()-1,arr[curr]-arr[temp]);
}
stk.push_back(curr);
root->update(curr,curr,arr[curr]);
while (!pq.empty() && pq.top().fi<arr[curr]){
root->update(pq.top().se,pq.top().se,INF);
pq.pop();
}
pq.push(ii(arr[curr],curr));
}
//cout<<root->query(it.l,it.r)<<endl;
ans[it.idx]=root->query(it.l,it.r)<=it.lim;
}
rep(x,0,q) cout<<ans[x]<<endl;
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In constructor 'node::node(int, int)':
sortbooks.cpp:39:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | s=_s,e=_e,m=s+e>>1;
| ~^~
# | 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... |