# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
651222 | alexccc | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++14 | 564 ms | 6324 KiB |
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>
#pragma GCC optimize("Ofast")
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
if(n <= 5000 && m <= 5000){
vector<long long> w(n + 1);
for(int i = 1; i <= n; i ++) cin >> w[i];
int l, r, k;
for(int i = 0; i < m; i ++){
cin >> l >> r >> k;
long long mx = w[l];
int check = 1;
for(int j = l; j <= r; j ++){
if(w[j] < mx && mx + w[j] > k){
check = 0;
break;
}
mx = max(mx,w[j]);
}
if(check==0)putchar('0');
else putchar('1');
putchar('\n');
}
}else{
bool flag = true;
int pre = 0;
vector<pair<int,int>> sub;
int left = 1, last = 0, now;
for(int i = 1; i <= n; i ++){
cin >> now;
if(now < last){
sub.push_back({left,i-1});//l to i-1 is increasing
left = i;
}
last = now;
}
int l,r,k,sz=sub.size();
for(int i=0;i<m;i++){
cin>>l>>r>>k;
int ind=lower_bound(sub.begin(),sub.end(),make_pair(l,r))-sub.begin();
if(r<=sub[ind].second){
putchar('1');
putchar('\n');
}else{
putchar('0');
putchar('\n');
}
}
}
return 0;
}
Compilation message (stderr)
# | 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... |