이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define maxn 800010
using namespace std;
int n, m, a[maxn], allR[maxn], ans;
vector<int> sorted[maxn];
void init(int idx, int l, int r){
if(l == r){
sorted[idx]={a[l]};
return;
}
int mid = (r+l)/2;
init(idx*2+1, l, mid);
init(idx*2+2, mid+1, r);
sorted[idx].resize(sorted[idx*2+1].size()+sorted[idx*2+2].size());
int tmp = lower_bound(sorted[idx*2+2].begin(), sorted[idx*2+2].end(), sorted[idx*2+1].back()) - sorted[idx*2+2].begin();
--tmp;
allR[idx] = max(allR[idx*2+1], allR[idx*2+2]);
if(tmp >= 0){
allR[idx] = max(allR[idx], sorted[idx*2+2][tmp] + sorted[idx*2+1].back() );
}
merge(sorted[idx*2+1].begin(), sorted[idx*2+1].end(), sorted[idx*2+2].begin(), sorted[idx*2+2].end(), sorted[idx].begin());
}
vector<int> allIx;
int query(int idx, int l, int r, int ql, int qr){
if(l >= ql and r <= qr){
allIx.push_back(idx);
return allR[idx];
}
if(l > qr or r<ql){
return 0;
}
int mid = (l+r)/2;
return max(query(idx*2+1, l, mid, ql, qr),query(idx*2+2, mid+1, r, ql, qr));
}
int main(){
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; ++i){
cin >> a[i];
}
init(0, 0, n-1);
for(int i = 0; i < m; ++i){
int l,r,k;
cin>>l>>r>>k;
--l, --r;
allIx.clear();
int tmp = query(0,0, n-1,l,r), pr = -1;
sort(allIx.begin(), allIx.end());
for(int i1 = 0; i1 < allIx.size();++i1){
int j = allIx[i1];
int tmpIdx=lower_bound(sorted[j].begin(), sorted[j].end(),pr)-sorted[j].begin();
--tmpIdx;
if(tmpIdx >= 0){
tmp = max(sorted[j][tmpIdx] + pr, tmp);
}
pr = max(pr, sorted[j].back());
}
cout << (tmp<=k) << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i1 = 0; i1 < allIx.size();++i1){
| ~~~^~~~~~~~~~~~~~
# | 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... |