Submission #962240

# Submission time Handle Problem Language Result Execution time Memory
962240 2024-04-13T09:33:11 Z Cookie Simple game (IZhO17_game) C++14
100 / 100
47 ms 10476 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7, pr = 31;
const int mxn = 1e6 + 5, mxq = 1e5 + 5, sq = 450, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e9 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
int n, m;
int bit[mxn + 1], h[mxn + 1];
void upd(int p, int v){
    while(p <= mxn){
        bit[p] += v; p += p & (-p);
    }
}
int get(int p){
    int ans = 0;
    while(p){
        ans += bit[p]; p -= p & (-p);
    }
    return(ans);
}
void upd(int l, int r, int v){
    if(l > r)swap(l, r);
    upd(l, v); upd(r + 1, -v);
}
void solve(){
    cin >> n >> m;
    for(int i = 1; i <= n; i++)cin >> h[i];
    for(int i = 1; i < n; i++){
        upd(h[i], h[i + 1], 1);
    }
    for(int i = 0; i < m; i++){
        int idq; cin >> idq;
        if(idq == 1){
            int pos, val; cin >> pos >> val;
            if(pos > 1)upd(h[pos - 1], h[pos], -1);
            if(pos < n)upd(h[pos], h[pos + 1], -1);
            h[pos] = val;
            if(pos > 1)upd(h[pos - 1], h[pos], 1);
            if(pos < n)upd(h[pos], h[pos + 1], 1);
        }else{
            int v; cin >> v;
            cout << get(v) << "\n";
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("netw.inp", "r", stdin);
    //freopen("netw.out", "w", stdout)
    int tt; tt = 1;
    while(tt--){
        solve();
 
    }
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 3 ms 5804 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 3 ms 5804 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 30 ms 7764 KB Output is correct
9 Correct 31 ms 10432 KB Output is correct
10 Correct 33 ms 10320 KB Output is correct
11 Correct 28 ms 7516 KB Output is correct
12 Correct 29 ms 8528 KB Output is correct
13 Correct 32 ms 8600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 3 ms 5804 KB Output is correct
4 Correct 2 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 30 ms 7764 KB Output is correct
9 Correct 31 ms 10432 KB Output is correct
10 Correct 33 ms 10320 KB Output is correct
11 Correct 28 ms 7516 KB Output is correct
12 Correct 29 ms 8528 KB Output is correct
13 Correct 32 ms 8600 KB Output is correct
14 Correct 40 ms 10324 KB Output is correct
15 Correct 47 ms 10268 KB Output is correct
16 Correct 40 ms 10400 KB Output is correct
17 Correct 41 ms 10476 KB Output is correct
18 Correct 42 ms 10432 KB Output is correct