답안 #524182

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524182 2022-02-08T18:27:10 Z nickmet2004 Simple game (IZhO17_game) C++11
100 / 100
168 ms 11204 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e6 + 5;
int n,m, a[N],  F[2000005];
void upd(int i , int d){
    while(i <= 2*N){
        F[i] += d;
        i += i & -i;
    }
}
int get(int i){
    int s= 0;
    while(i){
        s += F[i] , i -= i&-i;
    }
    return s;
}
void M(int A , int p , int h){
    if(A > h){
        upd(h , +1);
        if(a[p] >= A){
            upd(a[p] + 1 , +1);
            upd(A , -1);upd(A + 1 , -1);
        }
        else {
            upd(a[p] , -1);
        }
    }else {
        upd(h + 1 , -1);
        if(a[p] >= A){
            upd(a[p]+ 1 , +1);
        }else {
            upd(a[p] , -1);
            upd(A +1 , +1);
            upd(A , +1);
        }
    }
}
 main (){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n>>m;
    for(int i =1; i<= n; ++i)cin>>a[i];
    for(int i = 1; i< n; ++i){
        int x = a[i] , y = a[i + 1];
        if(x > y)swap(x , y);
        upd(x , 1),
        upd(y + 1 ,-1);
    }
    while(m--){
        int x;
        cin >> x;
        if(x==1){
            int p , h;
            cin >> p >> h;
            int A=-1 , B=-1;
            if(p==1) A = a[p+1];
            else if(p==n) B = a[p-1];
            else A = a[p-1] , B = a[p+1];
            if(A != -1)M(A , p , h);
            if(B != -1) M(B , p , h);
            a[p]=h;
        }else {
            int h;cin>>h;
            cout << get(h)<<endl;
        }
    }
}

Compilation message

game.cpp:40:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   40 |  main (){
      |  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 4 ms 6860 KB Output is correct
3 Correct 4 ms 6604 KB Output is correct
4 Correct 4 ms 6744 KB Output is correct
5 Correct 4 ms 6732 KB Output is correct
6 Correct 4 ms 6848 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 4 ms 6860 KB Output is correct
3 Correct 4 ms 6604 KB Output is correct
4 Correct 4 ms 6744 KB Output is correct
5 Correct 4 ms 6732 KB Output is correct
6 Correct 4 ms 6848 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 145 ms 1332 KB Output is correct
9 Correct 168 ms 9464 KB Output is correct
10 Correct 156 ms 9468 KB Output is correct
11 Correct 145 ms 1280 KB Output is correct
12 Correct 149 ms 1852 KB Output is correct
13 Correct 155 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 4 ms 6860 KB Output is correct
3 Correct 4 ms 6604 KB Output is correct
4 Correct 4 ms 6744 KB Output is correct
5 Correct 4 ms 6732 KB Output is correct
6 Correct 4 ms 6848 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 145 ms 1332 KB Output is correct
9 Correct 168 ms 9464 KB Output is correct
10 Correct 156 ms 9468 KB Output is correct
11 Correct 145 ms 1280 KB Output is correct
12 Correct 149 ms 1852 KB Output is correct
13 Correct 155 ms 1792 KB Output is correct
14 Correct 119 ms 9148 KB Output is correct
15 Correct 127 ms 11156 KB Output is correct
16 Correct 119 ms 11204 KB Output is correct
17 Correct 127 ms 11140 KB Output is correct
18 Correct 124 ms 11076 KB Output is correct