이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MP make_pair
#define ft first
#define sd second
#define pii pair<int, int>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 100100;
const int oo = 2e9;
ordered_set<pii> lf, rt;
int h[N], n, m;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> h[i];
lf.clear();
rt.clear();
for (int i = 1; i < n; i++) {
rt.insert(MP(max(h[i], h[i - 1]), i));
lf.insert(MP(min(h[i], h[i - 1]), i));
}
for (; m; m--){
int tp; cin >> tp;
if (tp == 1){
int ps, vl;
cin >> ps >> vl;
ps--;
if (ps > 0){
rt.erase(MP(max(h[ps], h[ps - 1]), ps));
lf.erase(MP(min(h[ps], h[ps - 1]), ps));
}
if (ps < n - 1){
rt.erase(MP(max(h[ps], h[ps + 1]), ps + 1));
lf.erase(MP(min(h[ps], h[ps + 1]), ps + 1));
}
h[ps] = vl;
if (ps > 0){
rt.insert(MP(max(h[ps], h[ps - 1]), ps));
lf.insert(MP(min(h[ps], h[ps - 1]), ps));
}
if (ps < n - 1){
rt.insert(MP(max(h[ps], h[ps + 1]), ps + 1));
lf.insert(MP(min(h[ps], h[ps + 1]), ps + 1));
}
} else {
int vl; cin >> vl;
int lef = rt.order_of_key(MP(vl, -oo));
int rgt = n - 1 - lf.order_of_key(MP(vl, +oo));
cout << n - 1 - lef - rgt << '\n';
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |