Submission #1125904

#TimeUsernameProblemLanguageResultExecution timeMemory
1125904LucaIlieSimple game (IZhO17_game)C++20
0 / 100
3 ms4160 KiB
#include <bits/stdc++.h> using namespace std; struct AIB { int n; vector<int> aib; void init( int _n ) { n = _n; aib.resize( n + 1 ); } void update( int i, int x ) { while ( i <= n ) { aib[i] += x; i += (i & -i); } } int query( int i ) { int s = 0; while ( i > 0 ) { s += aib[i]; i -= (i & -i); } return s; } } aib; const int MAX_N = 1e5; int h[MAX_N]; void update( int i, int j, int s ) { int l = min( h[i], h[j] ), r = max( h[i], h[j] ); if ( l == r ) return; aib.update( l + 1, s ); aib.update( r, -s ); } int main() { int n, q; cin >> n >> q; for ( int i = 1; i <= n; i++ ) cin >> h[i]; aib.init( (int)1e6 + 1 ); for ( int i = 1; i < n; i++ ) update( i, i + 1, 1 ); for ( int i = 0; i < q; i++ ) { int t; cin >> t; if ( t == 1 ) { int p, x; cin >> p >> x; if ( p > 1 ) update( p, p - 1, -1 ); if ( p < n ) update( p, p + 1, -1 ); h[p] = x; if ( p > 1 ) update( p, p - 1, 1 ); if ( p < n ) update( p, p + 1, 1 ); } else { int c; cin >> c; cout << aib.query( c ); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...