Submission #169928

#TimeUsernameProblemLanguageResultExecution timeMemory
169928stefdascaSimple game (IZhO17_game)C++14
100 / 100
305 ms17508 KiB
#include<bits/stdc++.h> #define god dimasi5eks #pragma GCC optimize("O3") #define fi first #define se second #define pb push_back #define pf push_front #define mod 1000000007 #define dancila 3.14159265359 #define eps 1e-9 using namespace std; typedef long long ll; int n, q; int v[100002]; int aint[4000002]; int lazy[4000002]; void lz(int nod, int st, int dr) { if(st != dr) { lazy[nod << 1] += lazy[nod]; lazy[nod << 1|1] += lazy[nod]; } else aint[nod] += lazy[nod]; lazy[nod] = 0; } void add(int nod, int st, int dr, int L, int R, int vv) { lz(nod, st, dr); if(dr < L || st > R) return; if(L <= st && dr <= R) { lazy[nod] += vv; lz(nod, st, dr); return; } int mid = (st + dr) / 2; add(nod << 1, st, mid, L, R, vv); add(nod << 1|1, mid + 1, dr, L, R, vv); } int query(int nod, int st, int dr, int x) { lz(nod, st, dr); if(st == dr) return aint[nod]; int mid = (st + dr) / 2; if(x <= mid) query(nod << 1, st, mid, x); else query(nod << 1|1, mid+1, dr, x); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> q; for(int i = 1; i <= n; ++i) cin >> v[i]; for(int i = 1; i < n; ++i) add(1, 1, 1000000, min(v[i], v[i+1]), max(v[i], v[i+1]), 1); for(int i = 1; i <= q; ++i) { int tip; cin >> tip; if(tip == 1) { int pos, val; cin >> pos >> val; if(pos != 1) add(1, 1, 1000000, min(v[pos - 1], v[pos]), max(v[pos - 1], v[pos]), -1); if(pos != n) add(1, 1, 1000000, min(v[pos + 1], v[pos]), max(v[pos + 1], v[pos]), -1); v[pos] = val; if(pos != 1) add(1, 1, 1000000, min(v[pos - 1], v[pos]), max(v[pos - 1], v[pos]), 1); if(pos != n) add(1, 1, 1000000, min(v[pos + 1], v[pos]), max(v[pos + 1], v[pos]), 1); } else { int pos; cin >> pos; cout << query(1, 1, 1000000, pos) << '\n'; } } return 0; }

Compilation message (stderr)

game.cpp: In function 'int query(int, int, int, int)':
game.cpp:56:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...