답안 #516866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516866 2022-01-22T07:49:36 Z Tenis0206 Employment (JOI16_employment) C++11
0 / 100
3 ms 844 KB
#include <bits/stdc++.h>

using namespace std;

const int VMAX = 1e6;

struct query_initial
{
    int tip, poz, val;
};

query_initial Q[VMAX+5];

int n,q;
int v[VMAX+5];

vector<int> a;

int aib[VMAX+5];

int ub(int x)
{
    return (x&(-x));
}

void update(int poz, int val)
{
    for(int i=poz;i<=VMAX;i+=ub(i))
    {
        aib[i] += val;
    }
}

int query(int poz)
{
    int rez = 0;
    for(int i=poz;i>=1;i-=ub(i))
    {
        rez += aib[i];
    }
    return rez;
}

void update_array(int poz, int val)
{
    if(v[poz]>v[poz-1])
    {
        update(v[poz-1]+1,-1);
        update(v[poz]+1,+1);
    }
    if(v[poz+1]>v[poz])
    {
        update(v[poz]+1,-1);
        update(v[poz+1]+1,+1);
    }
    v[poz] = val;
    if(v[poz]>v[poz-1])
    {
        update(v[poz-1]+1,+1);
        update(v[poz]+1,-1);
    }
    if(v[poz+1]>v[poz])
    {
        update(v[poz]+1,+1);
        update(v[poz+1]+1,-1);
    }
}

void update_init(int poz)
{
    if(v[poz]>v[poz-1])
    {
        update(v[poz-1]+1,+1);
        update(v[poz]+1,-1);
    }
}

int get_poz(int val)
{
    int st = 1;
    int dr = a.size();
    int poz = 0;
    while(st<=dr)
    {
        int mij = (st+dr>>1);
        if(a[mij-1]<=val)
        {
            poz = val;
            st = mij+1;
        }
        else
        {
            dr = mij-1;
        }
    }
    return poz;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        a.push_back(v[i]);
    }
    for(int i=1;i<=q;i++)
    {
        cin>>Q[i].tip;
        if(Q[i].tip==1)
        {
            cin>>Q[i].val;
            a.push_back(Q[i].val);
        }
        else
        {
            cin>>Q[i].poz>>Q[i].val;
            a.push_back(Q[i].val);
        }
    }
    sort(a.begin(),a.end());
    for(int i=1;i<=n;i++)
    {
        v[i] = get_poz(v[i]);
        update_init(i);
    }
    for(int i=1;i<=q;i++)
    {
        if(Q[i].tip==1)
        {
            int val = get_poz(Q[i].val);
            cout<<query(val)<<'\n';
        }
        else
        {
            int poz = Q[i].poz;
            int val = get_poz(Q[i].val);
            update_array(poz,val);
        }
    }
    return 0;
}

Compilation message

employment.cpp: In function 'int get_poz(int)':
employment.cpp:85:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   85 |         int mij = (st+dr>>1);
      |                    ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Runtime error 2 ms 588 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Runtime error 3 ms 844 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Runtime error 2 ms 588 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -