답안 #758265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758265 2023-06-14T10:28:23 Z vjudge1 Simple game (IZhO17_game) C++17
100 / 100
55 ms 5152 KB
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 1000007
#define INF 1000000000000000000
//#define ll long long
///#define cin fin
///#define cout fout
#define fi first
#define se second
using namespace std;
double const EPS = 1e-14;
///ofstream fout("herding.out");
///ifstream fin("herding.in");
const int Max = 1e6 + 5;
const int M = 1e6;
int ans[Max];

int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    int n, m; cin >> n >> m; int arr[n];
    for(int i = 0; i < n; i++) cin >> arr[i];

    for(int i = 1; i < n; i++) {
        if(arr[i-1] < arr[i]) {
            for(int j = arr[i-1]; j <= M; j += -j&j) {
                ans[j] += 1;
            }
            for(int j = arr[i]+1; j <= M; j += -j&j) {
                ans[j] -= 1;
            }
        }
        else {
            for(int j = arr[i]; j <= M; j += -j&j) {
                ans[j] += 1;
            }
            for(int j = arr[i-1]+1; j <= M; j += -j&j) {
                ans[j] -= 1;
            }
        }
    }
    while(m--) {
        int ty; cin >> ty;
        if(ty == 1) {
            int pos, val; cin >> pos >> val;
            pos--;
            if(pos > 0) {
                if(arr[pos-1] < arr[pos]) {
                    for(int j = arr[pos-1]; j <= M; j += -j&j) {
                        ans[j] -= 1;
                    }
                    for(int j = arr[pos]+1; j <= M; j += -j&j) {
                        ans[j] += 1;
                    }
                } else {
                    for(int j = arr[pos]; j <= M; j += -j&j) {
                        ans[j] -= 1;
                    }
                    for(int j = arr[pos-1]+1; j <= M; j += -j&j) {
                        ans[j] += 1;
                    }
                }
                if(arr[pos-1] < val) {
                    for(int j = arr[pos-1]; j <= M; j += -j&j) {
                        ans[j] += 1;
                    }
                    for(int j = val+1; j <= M; j += -j&j) {
                        ans[j] -= 1;
                    }

                } else {
                    for(int j = val; j <= M; j += -j&j) {
                        ans[j] += 1;
                    }
                    for(int j = arr[pos-1]+1; j <= M; j += -j&j) {
                        ans[j] -= 1;
                    }
                }

            }
            if(pos < n-1) {
                if(arr[pos+1] < arr[pos]) {
                    for(int j = arr[pos+1]; j <= M; j += -j&j) {
                        ans[j] -= 1;
                    }
                    for(int j = arr[pos]+1; j <= M; j += -j&j) {
                        ans[j] += 1;
                    }
                } else {
                    for(int j = arr[pos]; j <= M; j += -j&j) {
                        ans[j] -= 1;
                    }
                    for(int j = arr[pos+1]+1; j <= M; j += -j&j) {
                        ans[j] += 1;
                    }
                }
                if(arr[pos+1] < val) {
                    for(int j = arr[pos+1]; j <= M; j += -j&j) {
                        ans[j] += 1;
                    }
                    for(int j = val+1; j <= M; j += -j&j) {
                        ans[j] -= 1;
                    }

                } else {
                    for(int j = val; j <= M; j += -j&j) {
                        ans[j] += 1;
                    }
                    for(int j = arr[pos+1]+1; j <= M; j += -j&j) {
                        ans[j] -= 1;
                    }
                }
            }
            arr[pos] = val;
        }
        else {
            int h; cin >> h; int sum = 0;
            for(int j = h; j > 0; j -= -j&j) {
                sum += ans[j];
            }
            cout << sum << endl;
        }
    }

 return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 4052 KB Output is correct
3 Correct 2 ms 3924 KB Output is correct
4 Correct 2 ms 4052 KB Output is correct
5 Correct 3 ms 3924 KB Output is correct
6 Correct 3 ms 4052 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 4052 KB Output is correct
3 Correct 2 ms 3924 KB Output is correct
4 Correct 2 ms 4052 KB Output is correct
5 Correct 3 ms 3924 KB Output is correct
6 Correct 3 ms 4052 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 33 ms 852 KB Output is correct
9 Correct 38 ms 5152 KB Output is correct
10 Correct 39 ms 5128 KB Output is correct
11 Correct 31 ms 884 KB Output is correct
12 Correct 35 ms 1336 KB Output is correct
13 Correct 37 ms 1324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 3 ms 4052 KB Output is correct
3 Correct 2 ms 3924 KB Output is correct
4 Correct 2 ms 4052 KB Output is correct
5 Correct 3 ms 3924 KB Output is correct
6 Correct 3 ms 4052 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 33 ms 852 KB Output is correct
9 Correct 38 ms 5152 KB Output is correct
10 Correct 39 ms 5128 KB Output is correct
11 Correct 31 ms 884 KB Output is correct
12 Correct 35 ms 1336 KB Output is correct
13 Correct 37 ms 1324 KB Output is correct
14 Correct 46 ms 4888 KB Output is correct
15 Correct 55 ms 4824 KB Output is correct
16 Correct 47 ms 4808 KB Output is correct
17 Correct 54 ms 4812 KB Output is correct
18 Correct 48 ms 4888 KB Output is correct