Submission #393500

#TimeUsernameProblemLanguageResultExecution timeMemory
393500SavicSSimple game (IZhO17_game)C++14
100 / 100
215 ms10828 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define ff(i,a,b) for(int i=a;i<=b;i++) #define fb(i,b,a) for(int i=b;i>=a;i--) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int,int> pii; const int maxn = 100005; const int inf = 1e9 + 5; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) int n, q; int niz[maxn]; const int N = (int)1e6 + 5; ll dud[N]; void upd(int x, ll val) { while(x <= N) { dud[x] += val; x += x&(-x); } } ll query(int x) { ll sum = 0; while(x > 0) { sum += dud[x]; x -= x&(-x); } return sum; } int main() { ios::sync_with_stdio(false); cout.tie(nullptr); cin.tie(nullptr); cin >> n >> q; ff(i,1,n)cin >> niz[i]; ff(i,1,n - 1) { int mn = min(niz[i], niz[i + 1]); int mx = max(niz[i], niz[i + 1]); upd(mn, 1); upd(mx + 1, -1); } while(q--) { int tip; cin >> tip; if(tip == 1) { int pos, val; cin >> pos >> val; if(pos > 1) { upd(min(niz[pos - 1], niz[pos]), -1); upd(max(niz[pos - 1], niz[pos]) + 1, 1); } if(pos < n) { upd(min(niz[pos], niz[pos + 1]), -1); upd(max(niz[pos], niz[pos + 1]) + 1, 1); } niz[pos] = val; if(pos > 1) { upd(min(niz[pos - 1], niz[pos]), 1); upd(max(niz[pos - 1], niz[pos]) + 1, -1); } if(pos < n) { upd(min(niz[pos], niz[pos + 1]), 1); upd(max(niz[pos], niz[pos + 1]) + 1, -1); } } if(tip == 2) { int H; cin >> H; cout << query(H) << endl; } } return 0; } /** 3 3 1 5 1 2 3 1 1 5 2 3 // probati bojenje sahovski ili slicno **/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...