답안 #483509

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483509 2021-10-30T06:22:49 Z ak2006 Simple game (IZhO17_game) C++14
0 / 100
33 ms 78532 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll maxX = 2e6;
vl bit(4 * maxX);
void add(ll i,ll v)
{
    for (;i<=maxX;i += i & (-i))bit[i] += v;
}
void add(ll l,ll r,ll v)
{
    if (l > r)swap(l,r);
    add(l,v);
    add(r + 1,-1);
}
ll get(ll i)
{
    ll ret = 0;
    for (;i>0;i -= i &(-i))ret += bit[i];
    return ret;
}
vl h(maxX);
int main()
{
    fast;
    ll n,q;
    cin>>n>>q;
    for (ll i = 1;i<=n;i++){
        cin>>h[i];
        if (i >= 2)
            add(h[i - 1],h[i],1);
    }
    while (q--){
        ll t;
        cin>>t;
        if (t == 1){
            ll p,v;
            cin>>p>>v;
            if (p >= 2){
                add(h[p - 1],h[p],-1);
                add(h[p - 1],v,1);
            }
            if (p < n){
                add(h[p],h[p + 1],-1);
                add(v,h[p + 1],1);
            }
            h[p] = v;
        }
        else{
            ll H;
            cin>>H;
            cout<<get(H)<<"\n";
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 78532 KB Output is correct
2 Incorrect 33 ms 78516 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 78532 KB Output is correct
2 Incorrect 33 ms 78516 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 78532 KB Output is correct
2 Incorrect 33 ms 78516 KB Output isn't correct
3 Halted 0 ms 0 KB -