답안 #910086

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
910086 2024-01-17T21:22:03 Z raphaelp Simple game (IZhO17_game) C++14
100 / 100
181 ms 6920 KB
#include <bits/stdc++.h>
using namespace std;
#define LSOne(S) ((S) & (-S))

class FenwickTree
{
private:
    vector<int> ft;

public:
    FenwickTree(int x)
    {
        ft.assign(x, 0);
    }
    void update(int a, int b, int val)
    {
        for (int x = b; x; x -= LSOne(x))
            ft[x] += val;
        for (int x = a; x; x -= LSOne(x))
            ft[x] -= val;
    }
    int PSQ(int x)
    {
        int tot = 0;
        for (; x < ft.size(); x += LSOne(x))
            tot += ft[x];
        return tot;
    }
};
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> Tab(N);
    FenwickTree FT(1000010);
    for (int i = 0; i < N; i++)
    {
        cin >> Tab[i];
        if (i != 0)
        {
            FT.update(min(Tab[i], Tab[i - 1]), max(Tab[i], Tab[i - 1]), 1);
        }
    }
    for (int i = 0; i < M; i++)
    {
        int a;
        cin >> a;
        if (a == 1)
        {
            int p, val;
            cin >> p >> val;
            p--;
            if (p != 0)
                FT.update(min(Tab[p], Tab[p - 1]), max(Tab[p], Tab[p - 1]), -1);
            if (p != N - 1)
                FT.update(min(Tab[p], Tab[p + 1]), max(Tab[p], Tab[p + 1]), -1);
            Tab[p] = val;
            if (p != 0)
                FT.update(min(Tab[p], Tab[p - 1]), max(Tab[p], Tab[p - 1]), 1);
            if (p != N - 1)
                FT.update(min(Tab[p], Tab[p + 1]), max(Tab[p], Tab[p + 1]), 1);
        }
        else
        {
            int x;
            cin >> x;
            cout << FT.PSQ(x) << '\n';
        }
    }
}

Compilation message

game.cpp: In member function 'int FenwickTree::PSQ(int)':
game.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (; x < ft.size(); x += LSOne(x))
      |                ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 3 ms 4188 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 4 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 3 ms 4188 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 4 ms 4188 KB Output is correct
8 Correct 157 ms 4696 KB Output is correct
9 Correct 181 ms 5204 KB Output is correct
10 Correct 181 ms 5168 KB Output is correct
11 Correct 149 ms 4780 KB Output is correct
12 Correct 171 ms 5204 KB Output is correct
13 Correct 170 ms 5252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 3 ms 4188 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 3 ms 4188 KB Output is correct
5 Correct 3 ms 4188 KB Output is correct
6 Correct 3 ms 4188 KB Output is correct
7 Correct 4 ms 4188 KB Output is correct
8 Correct 157 ms 4696 KB Output is correct
9 Correct 181 ms 5204 KB Output is correct
10 Correct 181 ms 5168 KB Output is correct
11 Correct 149 ms 4780 KB Output is correct
12 Correct 171 ms 5204 KB Output is correct
13 Correct 170 ms 5252 KB Output is correct
14 Correct 142 ms 6736 KB Output is correct
15 Correct 140 ms 6736 KB Output is correct
16 Correct 143 ms 6920 KB Output is correct
17 Correct 141 ms 6716 KB Output is correct
18 Correct 145 ms 6740 KB Output is correct