Submission #1134028

#TimeUsernameProblemLanguageResultExecution timeMemory
1134028zhasynSimple game (IZhO17_game)C++20
100 / 100
81 ms5188 KiB
#include <bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; #define F first #define S second typedef long long ll; #define pii pair <int, int> #define pll pair <ll, ll> typedef long double ld; const ll N = 1e6 + 1000, M = 1e6 + 10, len = 315, inf = 1e18; const ll mod = 1e9 + 7; ll um(ll a, ll b){ return (1LL * a * b) % mod; } ll subr(ll a, ll b){ return ((1LL * a - b) % mod + mod) % mod; } int a[N], n, m, fen[N]; void upd(int i, int delta){ for(; i < N; i = (i | (i + 1))){ fen[i] += delta; } } int get(int r){ int res = 0; for(; r >= 0; r = (r & (r + 1)) - 1){ res += fen[r]; } return res; } void make(int a, int b, int d){ upd(min(a, b), d); upd(max(a, b), -d); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> a[i]; if(i > 1) make(a[i - 1], a[i], 1); } for(int i = 0, code, x, pos; i < m; i++){ cin >> code >> x; if(code == 2){ cout << get(x) << endl; } else{ cin >> pos; if(x > 1) make(a[x - 1], a[x], -1); if(x < n) make(a[x], a[x + 1], -1); a[x] = pos; if(x > 1) make(a[x - 1], a[x], 1); if(x < n) make(a[x], a[x + 1], 1); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...