답안 #878368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878368 2023-11-24T08:57:52 Z alexdd Simple game (IZhO17_game) C++17
100 / 100
52 ms 6952 KB
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[100005];
int aib[1000005];
int qry(int poz)
{
    int aux=0;
    for(int i=poz;i>0;i-=(i&(-i)))
        aux+=aib[i];
    return aux;
}
void upd(int poz, int newv)
{
    for(int i=poz;i<=1000005;i+=(i&(-i)))
        aib[i]+=newv;
}
void adauga(int prec, int cur, int semn)
{
    if(prec>cur)
        swap(prec,cur);
    upd(prec,semn);
    upd(cur+1,-semn);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(i>1)
            adauga(a[i-1],a[i],1);
    }
    int tip,x,y;
    for(int i=0;i<m;i++)
    {
        cin>>tip;
        if(tip==1)
        {
            cin>>x>>y;
            if(x>1) adauga(a[x-1],a[x],-1);
            if(x<n) adauga(a[x],a[x+1],-1);
            a[x]=y;
            if(x>1) adauga(a[x-1],a[x],1);
            if(x<n) adauga(a[x],a[x+1],1);
        }
        else
        {
            cin>>x;
            cout<<qry(x)<<"\n";
        }
    }
    return 0;
}
/**

a[i-1] <= h <= a[i]

a[i-1] >= h >= a[i]

3 3
1 5 1
2 3
1 1 5
2 3

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4572 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4572 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 25 ms 5492 KB Output is correct
9 Correct 30 ms 6748 KB Output is correct
10 Correct 30 ms 6736 KB Output is correct
11 Correct 36 ms 5420 KB Output is correct
12 Correct 29 ms 6644 KB Output is correct
13 Correct 27 ms 6476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4572 KB Output is correct
5 Correct 1 ms 4700 KB Output is correct
6 Correct 2 ms 4700 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 25 ms 5492 KB Output is correct
9 Correct 30 ms 6748 KB Output is correct
10 Correct 30 ms 6736 KB Output is correct
11 Correct 36 ms 5420 KB Output is correct
12 Correct 29 ms 6644 KB Output is correct
13 Correct 27 ms 6476 KB Output is correct
14 Correct 52 ms 6736 KB Output is correct
15 Correct 39 ms 6736 KB Output is correct
16 Correct 41 ms 6852 KB Output is correct
17 Correct 39 ms 6952 KB Output is correct
18 Correct 45 ms 6848 KB Output is correct