This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define pii pair<int,int>
#define N 1000005
#define INF 1e9+5
#define sp " "
#define endl "\n"
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);
#define all(x) (x).begin(),(x).end()
#define ll long long
using namespace std;
int n,m,w[N],s[N],l,r,k,rq,lq,mx1,mx2;
int main(){
cin >> n >> m;
for(int i=0;i<n;i++){
cin >> w[i];
s[i]=w[i];
}
sort(s,s+n);
for(int i=0;i<m;i++){
cin >> l >> r >> k;
mx1=mx2=0;
rq=lq=l;
int j=l;
while(j<=r&&w[j]==s[j]){
j++;
}
if(j>r){
continue;
}
lq=j;
for(j;j<=r;j++){
if(w[j]!=s[j]){
rq=j;
}
}
for(int j=lq;j<=rq;j++){
if(w[i]>mx1){
mx2=mx1;
mx1=w[i];
}
else if(w[i]<=mx1&&w[i]>mx2){
mx2=w[i];
}
}
if(mx1+mx2>k){
cout << 0 << endl;
}
else{
cout << 1 << endl;
}
}
}
Compilation message (stderr)
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:37:13: warning: statement has no effect [-Wunused-value]
37 | for(j;j<=r;j++){
| ^
# | 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... |