답안 #1033431

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1033431 2024-07-24T20:21:24 Z hasan2006 Simple game (IZhO17_game) C++17
100 / 100
39 ms 6856 KB
#include <bits/stdc++.h>

using namespace std;

#define TL ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rall(s) s.rbegin(),s.rend()
#define all(s) s.begin(),s.end()
#define pb push_back
#define se second
#define fi first
#define ll long long
#define ld long double
#define YES cout<<"YES\n"
#define Yes cout<<"Yes\n"
#define yes cout<<"yes\n"
#define NO cout<<"NO\n"
#define No cout<<"No\n"
#define no cout<<"no\n"


const int N = 1e6 + 9 , mod = 1e9 + 7;
int a[N] , d[N]  ;

void ad(int x , int y){
    while(x <= 1000000)
        d[x] += y , x += (x & -x);
}


void add(int x , int y , int k){
    if(x > y)   swap(x , y);
    ad(x , k) , ad(y + 1 , -k);
}

ll get(int x){
    ll ans = 0;
    while(x > 0)
        ans += d[x] , x -= (x & -x);
    return ans;
}

void solve()
{
    int n , q , i , x , y ,  k ;
    cin>>n>>q;
    for(i = 1; i <= n; i++){
        cin>>a[i];
        if(i != 1)  add(a[i] , a[i - 1] , 1);
    }
    while(q--){
        cin>>k>>x;
        if(k == 1){
            cin>>y;
            if(x > 1)
                add(a[x - 1] , a[x] , -1) , add(a[x - 1] , y , 1);
            if(x < n)
                add(a[x + 1] , a[x] , -1) , add(a[x + 1] , y , 1);
            a[x] = y;
        }else {
            cout<<get(x)<<"\n";
        }
    }
}

int main(){
    TL;

    /*#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif*/
    int t = 1;
    //cin>>t;
    while(t--)
     {
        solve();
     }
}
// Author : حسن
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 4116 KB Output is correct
3 Correct 2 ms 4184 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 4116 KB Output is correct
3 Correct 2 ms 4184 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 23 ms 1648 KB Output is correct
9 Correct 28 ms 6748 KB Output is correct
10 Correct 27 ms 6740 KB Output is correct
11 Correct 28 ms 1732 KB Output is correct
12 Correct 25 ms 2896 KB Output is correct
13 Correct 28 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 4116 KB Output is correct
3 Correct 2 ms 4184 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 23 ms 1648 KB Output is correct
9 Correct 28 ms 6748 KB Output is correct
10 Correct 27 ms 6740 KB Output is correct
11 Correct 28 ms 1732 KB Output is correct
12 Correct 25 ms 2896 KB Output is correct
13 Correct 28 ms 2900 KB Output is correct
14 Correct 39 ms 6856 KB Output is correct
15 Correct 37 ms 6744 KB Output is correct
16 Correct 37 ms 6736 KB Output is correct
17 Correct 38 ms 6740 KB Output is correct
18 Correct 37 ms 6748 KB Output is correct