Submission #1102978

# Submission time Handle Problem Language Result Execution time Memory
1102978 2024-10-19T09:52:04 Z KasymK Simple game (IZhO17_game) C++17
100 / 100
52 ms 5200 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss secox
#define all(v) v.begin(), v.ex()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 1e5+5;
const int MAX = 1e6;
int v[N], F[MAX+7];

int main(){
    // freopen("file.txt", "r", stdin);
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i = 1; i <= n; ++i){
        int x;
        scanf("%d", &x);
        v[i] = x;
    }
    auto wow = [&](int k, int u) {
        for(; k <= MAX; k += k&-k)
            F[k] += u;
    };
    auto how = [&](int a, int b, int val) {
        if(a>b)
            swap(a, b);
        wow(a, val);
        wow(b+1, -val);
    };
    for(int i = 1; i < n; ++i)
        how(v[i], v[i+1], 1);
    while(q--){
        int op;
        scanf("%d", &op);
        if(op==1){
            int k, u;
            scanf("%d%d", &k, &u);
            if(k>1)
                how(v[k], v[k-1], -1);
            if(k<n)
                how(v[k], v[k+1], -1);
            v[k] = u;
            if(k>1)
                how(v[k], v[k-1], 1);
            if(k<n)
                how(v[k], v[k+1], 1);
            continue;
        }
        int k;
        scanf("%d", &k);
        int answer = 0;
        for(; k >= 1; k -= k&-k)
            answer += F[k];
        printf("%d\n", answer);
    }
    return 0;
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
game.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
game.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |         scanf("%d", &op);
      |         ~~~~~^~~~~~~~~~~
game.cpp:45:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |             scanf("%d%d", &k, &u);
      |             ~~~~~^~~~~~~~~~~~~~~~
game.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         scanf("%d", &k);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 2 ms 4860 KB Output is correct
3 Correct 2 ms 4688 KB Output is correct
4 Correct 2 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 2 ms 4860 KB Output is correct
3 Correct 2 ms 4688 KB Output is correct
4 Correct 2 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 37 ms 4688 KB Output is correct
9 Correct 37 ms 5192 KB Output is correct
10 Correct 36 ms 5200 KB Output is correct
11 Correct 32 ms 4688 KB Output is correct
12 Correct 35 ms 5060 KB Output is correct
13 Correct 36 ms 5084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 2 ms 4860 KB Output is correct
3 Correct 2 ms 4688 KB Output is correct
4 Correct 2 ms 4688 KB Output is correct
5 Correct 2 ms 4688 KB Output is correct
6 Correct 2 ms 4688 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 37 ms 4688 KB Output is correct
9 Correct 37 ms 5192 KB Output is correct
10 Correct 36 ms 5200 KB Output is correct
11 Correct 32 ms 4688 KB Output is correct
12 Correct 35 ms 5060 KB Output is correct
13 Correct 36 ms 5084 KB Output is correct
14 Correct 52 ms 5112 KB Output is correct
15 Correct 49 ms 4944 KB Output is correct
16 Correct 48 ms 4936 KB Output is correct
17 Correct 51 ms 4948 KB Output is correct
18 Correct 48 ms 4944 KB Output is correct