이 제출은 이전 버전의 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];
int lp[1000005];
struct node{
int s,e,m;
int mn,mx;
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);
mn=min(l->mn,r->mn);
mx=max(l->mx,r->mx);
}
else{
mn=mx=arr[s];
}
}
int query_mn(int i,int j){
if (s==i && e==j) return mn;
else if (j<=m) return l->query_mn(i,j);
else if (m<i) return r->query_mn(i,j);
else return min(l->query_mn(i,m),r->query_mn(m+1,j));
}
int query_mx(int i,int j){
if (s==i && e==j) return mx;
else if (j<=m) return l->query_mx(i,j);
else if (m<i) return r->query_mx(i,j);
else return max(l->query_mx(i,m),r->query_mx(m+1,j));
}
} *root;
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];
rep(x,0,n){
if (x==0 || arr[x-1]>arr[x]) lp[x]=x;
else lp[x]=lp[x-1];
}
root=new node(0,1000005);
int a,b,c;
while (q--){
cin>>a>>b>>c;
a--,b--;
if (lp[b]<=a){
cout<<1<<endl;
continue;
}
int lo=lp[b],hi=b+2,mi;
//rep(x,lo,hi) cout<<root->query_mx(a,x-1)<<" "<<arr[x]<<endl;
while (hi-lo>>1){
mi=lo+hi>>1;
if (mi==b+1 || root->query_mx(a,mi-1)<=arr[mi]) hi=mi;
else lo=mi;
}
//cout<<root->query_mn(a,lo)<<" "<<root->query_mx(a,lo)<<endl;
if (root->query_mn(a,lo)+root->query_mx(a,lo)<=c) cout<<1<<endl;
else cout<<0<<endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In constructor 'node::node(int, int)':
sortbooks.cpp:38:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | s=_s,e=_e,m=s+e>>1;
| ~^~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:97:12: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
97 | while (hi-lo>>1){
| ~~^~~
sortbooks.cpp:98:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
98 | mi=lo+hi>>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... |