답안 #563228

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
563228 2022-05-16T14:24:09 Z Tien_Noob Simple game (IZhO17_game) C++17
100 / 100
87 ms 6840 KB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 1e5, M = 1e6;
struct FenwickTree
{
    int Tree[M + 1];
    void add(int pos, int val)
    {
        for (; pos <= M; pos += (pos & (-pos)))
        {
            Tree[pos] += val;
        }
    }
    int sum(int pos)
    {
        int ret = 0;
        for (; pos > 0; pos -= (pos & (-pos)))
        {
            ret += Tree[pos];
        }
        return ret;
    }
    int sum(int l, int r)
    {
        return sum(r) - sum(l - 1);
    }
} tree;
int h[N + 1], n, q;
void read()
{
    cin >> n >> q;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> h[i];
        if (i > 1)
        {
            tree.add(min(h[i], h[i - 1]), 1);
            tree.add(max(h[i], h[i - 1]) + 1, -1);
        }
    }
}
void solve()
{
    while(q--)
    {
        int t;
        cin >> t;
        if (t == 1)
        {
            int i, a;
            cin >> i >> a;
            if (i < n)
            {
                tree.add(min(h[i], h[i + 1]), -1);
                tree.add(max(h[i], h[i + 1]) + 1, 1);
                tree.add(min(a, h[i + 1]), 1);
                tree.add(max(a, h[i + 1]) + 1, -1);
            }
            if (i > 1)
            {
                tree.add(min(h[i], h[i - 1]), -1);
                tree.add(max(h[i], h[i - 1]) + 1, 1);
                tree.add(min(a, h[i - 1]), 1);
                tree.add(max(a, h[i - 1]) + 1, -1);
            }
            h[i] = a;
        }
        else
        {
            int H;
            cin >> H;
            cout << tree.sum(H) << '\n';
        }
    }
}
int  main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:86:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 3 ms 4180 KB Output is correct
3 Correct 3 ms 4052 KB Output is correct
4 Correct 3 ms 4052 KB Output is correct
5 Correct 3 ms 4052 KB Output is correct
6 Correct 3 ms 4052 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 3 ms 4180 KB Output is correct
3 Correct 3 ms 4052 KB Output is correct
4 Correct 3 ms 4052 KB Output is correct
5 Correct 3 ms 4052 KB Output is correct
6 Correct 3 ms 4052 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 32 ms 1700 KB Output is correct
9 Correct 54 ms 6732 KB Output is correct
10 Correct 49 ms 6784 KB Output is correct
11 Correct 30 ms 1568 KB Output is correct
12 Correct 36 ms 2764 KB Output is correct
13 Correct 35 ms 2912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 3 ms 4180 KB Output is correct
3 Correct 3 ms 4052 KB Output is correct
4 Correct 3 ms 4052 KB Output is correct
5 Correct 3 ms 4052 KB Output is correct
6 Correct 3 ms 4052 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 32 ms 1700 KB Output is correct
9 Correct 54 ms 6732 KB Output is correct
10 Correct 49 ms 6784 KB Output is correct
11 Correct 30 ms 1568 KB Output is correct
12 Correct 36 ms 2764 KB Output is correct
13 Correct 35 ms 2912 KB Output is correct
14 Correct 87 ms 6780 KB Output is correct
15 Correct 72 ms 6800 KB Output is correct
16 Correct 53 ms 6732 KB Output is correct
17 Correct 55 ms 6840 KB Output is correct
18 Correct 56 ms 6776 KB Output is correct