Submission #522913

#TimeUsernameProblemLanguageResultExecution timeMemory
522913dostigatorSimple game (IZhO17_game)C++14
100 / 100
176 ms11240 KiB
#pragma GCC optimize("O3") #pragma GCC target("popcnt") #include <bits/stdc++.h> using namespace std; #define IShowSpeed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define popcnt __builtin_popcount #define all(a) a.begin(),a.end() #define pii pair<int,int> #define mii map<int,int> #define pll pair<ll,ll> #define mll map<ll,ll> #define pb push_back #define vt vector #define endl '\n' #define X first #define Y second typedef long double ld; typedef long long ll; const ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},N=1e6+10; const ll mod=1e9+7,inf=1e18; int n,q,y[N],t[4*N]; void upd(int v, int tl, int tr, int l, int r, int val) { if(tl >= l && tr <= r) { t[v] += val; return; } if(tl > r || l > tr) return; int mid = (tl + tr) >> 1; upd(v * 2, tl, mid, l, r, val); upd(v * 2 + 1, mid + 1, tr, l, r, val); } int get(int v, int tl, int tr, int id, int res) { res += t[v]; if(tl == tr) return res; int mid = (tl + tr) >> 1; if(id <= mid) return get(v * 2, tl, mid, id, res); else return get(v * 2 + 1, mid + 1, tr, id, res); } void solve(){ cin >> n >> q; for(int i = 1; i <= n; ++i) { cin >> y[i]; } for(int i = 1; i < n; ++i) { int l = min(y[i], y[i + 1]), r = max(y[i], y[i + 1]); upd(1, 1, 1e6, l, r, 1); } while(q--) { char tp; cin >> tp; int i, d; if(tp == '1') { cin >> i >> d; if(i < n) { int l = min(y[i], y[i + 1]), r = max(y[i], y[i + 1]); upd(1, 1, 1e6, l, r, -1); } if(i > 1) { int l = min(y[i], y[i - 1]), r = max(y[i], y[i - 1]); upd(1, 1, 1e6, l, r, -1); } y[i] = d; if(i < n) { int l = min(y[i], y[i + 1]), r = max(y[i], y[i + 1]); upd(1, 1, 1e6, l, r, 1); } if(i > 1) { int l = min(y[i], y[i - 1]), r = max(y[i], y[i - 1]); upd(1, 1, 1e6, l, r, 1); } } else { cin >> d; cout << get(1, 1, 1e6, d, 0) << endl; } } } int main() { IShowSpeed; int tt=1; //cin>>tt; while(tt--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...