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 endl "\n"
using namespace std;
const int maxn = 1e6+5;
int n,m;
int w[maxn],pref[maxn];
vector<int>pos[1001];
int bin_purvo(int i, int L, int R)
{
int l = 0, r = pos[i].size()-1;
int mid;
while(l<=r)
{
mid = (l+r)/2;
if(pos[i][mid]<L) l = mid+1;
else r = mid-1;
}
if(l != pos[i].size() && pos[i][l]<=R) return pos[i][l];
return -1;
}
int bin_posle(int i, int L, int R)
{
int l = 0, r = pos[i].size()-1;
int mid;
while(l<=r)
{
mid = (l+r)/2;
if(R<pos[i][mid]) r = mid-1;
else l = mid+1;
}
if(r != -1 && L<=pos[i][r]) return pos[i][r];
return -1;
}
bool check(int l, int r, int k)
{
vector<pair<int,int> >v;
for(int i = 0; i <= 1000; i++)
{
int ch1 = bin_purvo(i,l,r);
int ch2 = bin_posle(i,l,r);
if(ch1 != -1) v.push_back({ch1,i});
if(ch2 != -1 && ch2 != ch1) v.push_back({ch2,i});
}
sort(v.begin(),v.end());
int maxch = 0;
int razmqna = 0;
for(pair<int,int> wi : v)
{
if(maxch>wi.second) razmqna = max(razmqna,maxch+wi.second);
maxch = max(maxch,wi.second);
}
return k >= razmqna;
}
void read()
{
cin >> n >> m;
int minch = 1e9;
for(int i = 1; i <= n; i++)
{
cin >> w[i];
minch = min(minch,w[i]);
if(w[i]<=1000) pos[w[i]].push_back(i);
}
for(int i = 2; i <= n; i++)
{
pref[i] = pref[i-1];
if(w[i-1]<=w[i]) pref[i]++;
}
int l,r,k;
for(int i = 1; i <= m; i++)
{
cin >> l >> r >> k;
if(minch>k)
{
if(pref[r]-pref[l] == r-l) cout << 1 << endl;
else cout << 0 << endl;
}
else
{
if(check(l,r,k)) cout << 1 << endl;
else cout << 0 << endl;
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
read();
return 0;
}
Compilation message (stderr)
sortbooks.cpp: In function 'int bin_purvo(int, int, int)':
sortbooks.cpp:22:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if(l != pos[i].size() && pos[i][l]<=R) return pos[i][l];
| ~~^~~~~~~~~~~~~~~~
# | 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... |