Submission #879506

# Submission time Handle Problem Language Result Execution time Memory
879506 2023-11-27T15:06:22 Z sleepntsheep Simple game (IZhO17_game) C++17
100 / 100
41 ms 5320 KB
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include <complex>

using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

using namespace std;
using pt = complex<f80>;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,tune=native")

int n, m, h[100000], t[1000001];

void upd(int p, int k) { for (; p < sizeof t / sizeof *t; p+=p&-p) t[p]+=k; }
int qry(int p) { int z{0}; for(; p;p-=p&-p)z+=t[p];return z; }

void cal(int i, int k)
{
    if (h[i] > h[i-1]) upd(h[i-1]+1, k), upd(h[i]+1, -k);
    else if (h[i] < h[i-1]) upd(h[i]+1, k), upd(h[i-1]+1, -k);
}

int main()
{
    ShinLena;
    cin >> n >> m >> h[0];
    for (int i = 1; i < n; ++i) cin >> h[i], cal(i, 1);

    for (int t, x, y; m--;)
    {
        cin >> t >> x;
        if (t == 1)
        {
            --x; cin >> y;
            if (x) cal(x, -1);
            if (x + 1 < n) cal(x+1, -1);
            h[x] = y;
            if (x) cal(x, 1);
            if (x + 1 < n) cal(x+1, 1);
        }
        else cout << qry(x) << '\n';
    }

    return 0;
}


Compilation message

game.cpp: In function 'void upd(int, int)':
game.cpp:30:35: warning: comparison of integer expressions of different signedness: 'int' and 'long unsigned int' [-Wsign-compare]
   30 | void upd(int p, int k) { for (; p < sizeof t / sizeof *t; p+=p&-p) t[p]+=k; }
      |                                 ~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 25 ms 4700 KB Output is correct
9 Correct 33 ms 5320 KB Output is correct
10 Correct 30 ms 5212 KB Output is correct
11 Correct 21 ms 4700 KB Output is correct
12 Correct 28 ms 5212 KB Output is correct
13 Correct 28 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 25 ms 4700 KB Output is correct
9 Correct 33 ms 5320 KB Output is correct
10 Correct 30 ms 5212 KB Output is correct
11 Correct 21 ms 4700 KB Output is correct
12 Correct 28 ms 5212 KB Output is correct
13 Correct 28 ms 4956 KB Output is correct
14 Correct 41 ms 4956 KB Output is correct
15 Correct 40 ms 5028 KB Output is correct
16 Correct 41 ms 5032 KB Output is correct
17 Correct 40 ms 4956 KB Output is correct
18 Correct 39 ms 5036 KB Output is correct