Submission #1011520

#TimeUsernameProblemLanguageResultExecution timeMemory
1011520PringEmployment (JOI16_employment)C++17
100 / 100
661 ms131660 KiB
#include <bits/stdc++.h> using namespace std; #ifdef MIKU string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m"; #define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x) void dout() { cout << dbrs << endl; } template <typename T, typename ...U> void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); } #else #define debug(...) 39 #endif #define fs first #define sc second #define mp make_pair #define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++) using ll = long long; typedef pair<int, int> pii; const int MXN = 200005, INF = 1000000007; int n, q, a[MXN], b[MXN]; pii operator+(pii a, pii b) { return mp(a.fs + b.fs, a.sc + b.sc); } struct PSMG { #define mid ((l + r) >> 1) int L[MXN * 60], R[MXN * 60], nc; pii val[MXN * 60]; void init() { nc = 2; } int modify(int id, int l, int r, int p, pii v) { if (id == 0) id = nc++; // debug(id, l, r, p); if (l + 1 == r) { val[id] = val[id] + v; return id; } if (p < mid) L[id] = modify(L[id], l, mid, p, v); else R[id] = modify(R[id], mid, r, p, v); val[id] = val[L[id]] + val[R[id]]; return id; } pii query(int id, int l, int r, int _l, int _r) { if (_r <= l || r <= _l) return mp(0, 0); if (_l <= l && r <= _r) return val[id]; return query(L[id], l, mid, _l, _r) + query(R[id], mid, r, _l, _r); } #undef mid } smg; void PRE() { smg.init(); FOR(i, 0, n - 1) b[i] = min(a[i], a[i + 1]); FOR(i, 0, n) smg.modify(1, 0, INF, a[i], mp(1, 0)); FOR(i, 0, n - 1) smg.modify(1, 0, INF, b[i], mp(0, 1)); } void MODIFY(int p, int v) { smg.modify(1, 0, INF, a[p], mp(-1, 0)); if (p) smg.modify(1, 0, INF, b[p - 1], mp(0, -1)); if (p != n - 1) smg.modify(1, 0, INF, b[p], mp(0, -1)); a[p] = v; if (p) b[p - 1] = min(a[p - 1], a[p]); if (p != n - 1) b[p] = min(a[p], a[p + 1]); smg.modify(1, 0, INF, a[p], mp(1, 0)); if (p) smg.modify(1, 0, INF, b[p - 1], mp(0, 1)); if (p != n - 1) smg.modify(1, 0, INF, b[p], mp(0, 1)); } int QUERY(int bnd) { auto [x, y] = smg.query(1, 0, INF, bnd, INF); return x - y; } void miku() { int t, x, y; cin >> n >> q; FOR(i, 0, n) cin >> a[i]; PRE(); while (q--) { cin >> t; if (t == 1) { cin >> x; cout << QUERY(x) << '\n'; } else { cin >> x >> y; MODIFY(--x, y); } } } int32_t main() { cin.tie(0) -> sync_with_stdio(false); cin.exceptions(cin.failbit); miku(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...