답안 #85273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
85273 2018-11-19T02:36:31 Z mra2322001 Simple game (IZhO17_game) C++14
100 / 100
229 ms 22844 KB
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)

using namespace std;
typedef long long ll;
const int N = 100002;

int n, q, a[N], t[1000002], b[N], c[N];

void up(int x, int y, int id){
    for(x; x <= 1000000; x += (x & -x)) t[x] += id;
    for(y = y + 1; y <= 1000000; y += (y & -y)) t[y] -= id;
}

int get1(int x){
    if(x <= 0) return 0;
    int res = 0;
    for(x; x > 0; x -= (x & -x)) res += t[x];
    return res;
}

void solve(){
    int h; cin >> h;
    int x = get1(h);
    cout << x << endl;
}

int main(){
    ios_base::sync_with_stdio(0);

    cin >> n >> q;
    f1(i, n) cin >> a[i];
    for(int i = 2; i <= n; i++){
        b[i - 1] = min(a[i - 1], a[i]);
        c[i - 1] = max(a[i - 1], a[i]);
        up(b[i - 1] + 1, c[i - 1] - 1, 1);
    }
    while(q--){
        int type; cin >> type;
        if(type==2) solve();
        else{
            int i, x; cin >> i >> x;
            if(i > 1){
                up(b[i - 1] + 1, c[i - 1] - 1, -1);
                b[i - 1] = min(a[i - 1], x);
                c[i - 1] = max(a[i - 1], x);
                up(b[i - 1] + 1, c[i - 1] - 1, 1);
            }
            if(i < n){
                up(b[i] + 1, c[i] - 1, -1);
                b[i] = min(a[i + 1], x);
                c[i] = max(a[i + 1], x);
                up(b[i] + 1, c[i] - 1, 1);
            }
            a[i] = x;
        }
    }
}

Compilation message

game.cpp: In function 'void up(int, int, int)':
game.cpp:12:10: warning: statement has no effect [-Wunused-value]
     for(x; x <= 1000000; x += (x & -x)) t[x] += id;
          ^
game.cpp: In function 'int get1(int)':
game.cpp:19:10: warning: statement has no effect [-Wunused-value]
     for(x; x > 0; x -= (x & -x)) res += t[x];
          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 4344 KB Output is correct
3 Correct 6 ms 4344 KB Output is correct
4 Correct 6 ms 4344 KB Output is correct
5 Correct 6 ms 4344 KB Output is correct
6 Correct 6 ms 4344 KB Output is correct
7 Correct 5 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 4344 KB Output is correct
3 Correct 6 ms 4344 KB Output is correct
4 Correct 6 ms 4344 KB Output is correct
5 Correct 6 ms 4344 KB Output is correct
6 Correct 6 ms 4344 KB Output is correct
7 Correct 5 ms 4344 KB Output is correct
8 Correct 195 ms 4344 KB Output is correct
9 Correct 217 ms 8212 KB Output is correct
10 Correct 229 ms 9944 KB Output is correct
11 Correct 194 ms 9944 KB Output is correct
12 Correct 213 ms 9944 KB Output is correct
13 Correct 214 ms 9944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 4344 KB Output is correct
3 Correct 6 ms 4344 KB Output is correct
4 Correct 6 ms 4344 KB Output is correct
5 Correct 6 ms 4344 KB Output is correct
6 Correct 6 ms 4344 KB Output is correct
7 Correct 5 ms 4344 KB Output is correct
8 Correct 195 ms 4344 KB Output is correct
9 Correct 217 ms 8212 KB Output is correct
10 Correct 229 ms 9944 KB Output is correct
11 Correct 194 ms 9944 KB Output is correct
12 Correct 213 ms 9944 KB Output is correct
13 Correct 214 ms 9944 KB Output is correct
14 Correct 169 ms 15228 KB Output is correct
15 Correct 162 ms 17064 KB Output is correct
16 Correct 166 ms 19004 KB Output is correct
17 Correct 159 ms 20928 KB Output is correct
18 Correct 157 ms 22844 KB Output is correct