Submission #399958

#TimeUsernameProblemLanguageResultExecution timeMemory
399958abc864197532Simple game (IZhO17_game)C++17
100 / 100
202 ms6916 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define pb push_back #define eb emplace_back #define pii pair <int, int> #define X first #define Y second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define info() cerr << __PRETTY_FUNCTION__ << ": " << __LINE__ << endl #define test(args...) info(), abc("[" + string(#args) + "]", args) void abc() {cerr << endl;} template <typename T, typename ...U> void abc(T a, U ...b) { cerr << a << ' ', abc(b...); } template <typename T> void printv(T l, T r) { while (l != r) cout << *l << " \n"[++l == r]; } template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) { return o >> a.X >> a.Y; } template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) { return o << '(' << a.X << ", " << a.Y << ')'; } template <typename T> ostream& operator << (ostream& o, vector<T> a) { bool is = false; for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;} return o << '}'; } const int N = 1000087, logN = 20, K = 111; int bit[N]; void add(int p, int v) { p += 5; for (int i = p; i < N; i += i & (-i)) bit[i] += v; } int query(int p) { p += 5; int ans = 0; for (int i = p; i > 0; i -= i & (-i)) ans += bit[i]; return ans; } int main () { ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector <int> a(n); auto chg = [&](int i, int v) { if (i - 1 < 0 || i >= n) return; int mn = min(a[i - 1], a[i]), mx = max(a[i - 1], a[i]); add(mn + 1, v); add(mx, -v); }; for (int i = 0; i < n; ++i) { cin >> a[i]; chg(i, 1); } while (q--) { int t, p, x; cin >> t >> p; if (t == 1) { cin >> x, --p; chg(p, -1); chg(p + 1, -1); a[p] = x; chg(p, 1); chg(p + 1, 1); } else { cout << query(p) << endl; } } } /* 3 3 1 5 1 2 3 1 1 5 2 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...