제출 #173081

#제출 시각아이디문제언어결과실행 시간메모리
173081VEGAnnSimple game (IZhO17_game)C++14
100 / 100
566 ms15696 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...