Submission #768016

# Submission time Handle Problem Language Result Execution time Memory
768016 2023-06-27T11:23:40 Z raysh07 Simple game (IZhO17_game) C++17
100 / 100
65 ms 11164 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (int)1e18
#define f first
#define s second

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6;
int f[N + 1], a[N + 1];
int n, q;

void upd(int x, int v){
    for (int i = x; i <= N; i += i & (-i)){
        f[i] += v;
    }
}

int query(int x){
    int res = 0;
    for (int i = x; i; i -= i & (-i)){
        res += f[i];
    }
    
    return res;
}

void ok(int i, int orz){
    int mn = min(a[i], a[i - 1]);
    int mx = max(a[i], a[i - 1]);
    
    upd(mn, 1 * orz);
    upd(mx + 1, -1 * orz);
}

void Solve() 
{
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        
        if (i != 1) ok(i, 1);
    }
    
    while(q--){
        int t; cin >> t;
        
        if (t == 1){
            int p, v; cin >> p >> v;
            
            if (p != 1) ok(p, -1);
            if (p != n) ok(p + 1, -1);
            
            a[p] = v;
            
            if (p != 1) ok(p, 1);
            if (p != n) ok(p + 1, 1);
        } else {
            int x; cin >> x;
            
            cout << query(x) << "\n";
        }
    }
}

int32_t main() 
{
    auto begin = std::chrono::high_resolution_clock::now();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
 //   cin >> t;
    for(int i = 1; i <= t; i++) 
    {
        //cout << "Case #" << i << ": ";
        Solve();
    }
    auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 6612 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6612 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6740 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 6612 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6612 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6740 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 27 ms 2084 KB Output is correct
9 Correct 37 ms 11064 KB Output is correct
10 Correct 35 ms 11080 KB Output is correct
11 Correct 27 ms 2028 KB Output is correct
12 Correct 29 ms 3276 KB Output is correct
13 Correct 28 ms 3228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 6612 KB Output is correct
3 Correct 3 ms 6484 KB Output is correct
4 Correct 3 ms 6612 KB Output is correct
5 Correct 3 ms 6484 KB Output is correct
6 Correct 3 ms 6740 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 27 ms 2084 KB Output is correct
9 Correct 37 ms 11064 KB Output is correct
10 Correct 35 ms 11080 KB Output is correct
11 Correct 27 ms 2028 KB Output is correct
12 Correct 29 ms 3276 KB Output is correct
13 Correct 28 ms 3228 KB Output is correct
14 Correct 49 ms 11136 KB Output is correct
15 Correct 54 ms 11044 KB Output is correct
16 Correct 50 ms 11084 KB Output is correct
17 Correct 65 ms 11096 KB Output is correct
18 Correct 52 ms 11164 KB Output is correct