답안 #826528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826528 2023-08-15T16:24:27 Z Rifal Simple game (IZhO17_game) C++14
100 / 100
72 ms 6844 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 2 ms 4056 KB Output is correct
3 Correct 4 ms 4000 KB Output is correct
4 Correct 2 ms 4052 KB Output is correct
5 Correct 2 ms 4060 KB Output is correct
6 Correct 2 ms 4052 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 4056 KB Output is correct
3 Correct 4 ms 4000 KB Output is correct
4 Correct 2 ms 4052 KB Output is correct
5 Correct 2 ms 4060 KB Output is correct
6 Correct 2 ms 4052 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 29 ms 1744 KB Output is correct
9 Correct 68 ms 6844 KB Output is correct
10 Correct 35 ms 6840 KB Output is correct
11 Correct 29 ms 1508 KB Output is correct
12 Correct 32 ms 2904 KB Output is correct
13 Correct 30 ms 2736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 4056 KB Output is correct
3 Correct 4 ms 4000 KB Output is correct
4 Correct 2 ms 4052 KB Output is correct
5 Correct 2 ms 4060 KB Output is correct
6 Correct 2 ms 4052 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 29 ms 1744 KB Output is correct
9 Correct 68 ms 6844 KB Output is correct
10 Correct 35 ms 6840 KB Output is correct
11 Correct 29 ms 1508 KB Output is correct
12 Correct 32 ms 2904 KB Output is correct
13 Correct 30 ms 2736 KB Output is correct
14 Correct 51 ms 6720 KB Output is correct
15 Correct 72 ms 6840 KB Output is correct
16 Correct 47 ms 6732 KB Output is correct
17 Correct 51 ms 6740 KB Output is correct
18 Correct 45 ms 6812 KB Output is correct