이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
#define arr3 array<int, 3>
struct ST{
vector<int> a;
int n;
ST(int ns){
n = ns;
a.resize(n + 1);
}
void upd(int p, int x){
a[p] = x;
}
pii get(int l, int r){
pii mx = {0, 0};
for (int i = l; i <= r; i++){
mx = max(mx, {a[i], i});
}
return mx;
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) cin>>a[i];
for (int i = 1; i <= n; i++) cin>>b[i];
int q; cin>>q;
while (q--){
int l, r; cin>>l>>r;
vector<arr3> st;
for (int i = l; i <= r; i++){
st.pb({b[i], a[i], i});
}
sort(st.begin(), st.end());
vector<pii> x;
for (int i = 0; i < (int) st.size(); i++){
x.pb({st[i][1], i + 1});
}
sort(x.begin(), x.end());
ST T(n);
vector<int> p(n + 1), xx;
for (int i = 0; i < x.size(); i++){
T.upd(i + 1, x[i].ss);
p[x[i].ss - 1] = i + 1;
xx.pb(x[i].ff);
}
vector<int> :: iterator it;
set<pii> st1;
for (int i = 0; i < st.size(); i++) st1.insert({st[i][1], i});
bool ind = 1;
for (int j = st.size() - 1; j >= 0; j--){
it = lower_bound(xx.begin(), xx.end(), st[j][0]);
int ii = (int) (it - xx.begin()) + 1;
pii mx = max(T.get(ii, p[j] - 1), T.get(p[j] + 1, n));
if (!mx.ff){
bool k = (st1.find({st[j][1], j}) != st1.end());
if (k) st1.erase({st[j][1], j});
if (st1.empty()){
ind = 0;
break;
}
auto f = prev(st1.end());
if ((*f).ff < st[j][0]){
ind = 0;
break;
}
T.upd(p[(*f).ss], 0);
st1.erase(f);
if (k) st1.insert({st[j][1], j});
continue;
}
T.upd(mx.ss, 0);
int t = x[mx.ss - 1].ss - 1;
st1.erase({st[t][1], t});
T.upd(p[j], 0);
}
cout<<((ind) ? "Yes" : "No")<<"\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 0; i < x.size(); i++){
| ~~^~~~~~~~~~
Main.cpp:62:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (int i = 0; i < st.size(); i++) st1.insert({st[i][1], i});
| ~~^~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |