이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |