답안 #516874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
516874 2022-01-22T07:54:01 Z Tenis0206 Employment (JOI16_employment) C++11
100 / 100
199 ms 18512 KB
#include <bits/stdc++.h>
#define int long long

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 = mij;
            st = mij+1;
        }
        else
        {
            dr = mij-1;
        }
    }
    return poz;
}

signed 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 'long long int get_poz(long long int)':
employment.cpp:86:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   86 |         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 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 2 ms 464 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 472 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 12 ms 1868 KB Output is correct
5 Correct 23 ms 3100 KB Output is correct
6 Correct 38 ms 4932 KB Output is correct
7 Correct 67 ms 7036 KB Output is correct
8 Correct 74 ms 8892 KB Output is correct
9 Correct 137 ms 14896 KB Output is correct
10 Correct 116 ms 12468 KB Output is correct
11 Correct 151 ms 16496 KB Output is correct
12 Correct 172 ms 18184 KB Output is correct
13 Correct 173 ms 18100 KB Output is correct
14 Correct 167 ms 17844 KB Output is correct
15 Correct 172 ms 17888 KB Output is correct
16 Correct 172 ms 18476 KB Output is correct
17 Correct 171 ms 18368 KB Output is correct
18 Correct 171 ms 18436 KB Output is correct
19 Correct 193 ms 18356 KB Output is correct
20 Correct 173 ms 18484 KB Output is correct
# 결과 실행 시간 메모리 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 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 2 ms 464 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 464 KB Output is correct
12 Correct 2 ms 592 KB Output is correct
13 Correct 2 ms 472 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 464 KB Output is correct
16 Correct 2 ms 588 KB Output is correct
17 Correct 2 ms 588 KB Output is correct
18 Correct 2 ms 588 KB Output is correct
19 Correct 12 ms 1868 KB Output is correct
20 Correct 23 ms 3100 KB Output is correct
21 Correct 38 ms 4932 KB Output is correct
22 Correct 67 ms 7036 KB Output is correct
23 Correct 74 ms 8892 KB Output is correct
24 Correct 137 ms 14896 KB Output is correct
25 Correct 116 ms 12468 KB Output is correct
26 Correct 151 ms 16496 KB Output is correct
27 Correct 172 ms 18184 KB Output is correct
28 Correct 173 ms 18100 KB Output is correct
29 Correct 167 ms 17844 KB Output is correct
30 Correct 172 ms 17888 KB Output is correct
31 Correct 172 ms 18476 KB Output is correct
32 Correct 171 ms 18368 KB Output is correct
33 Correct 171 ms 18436 KB Output is correct
34 Correct 193 ms 18356 KB Output is correct
35 Correct 173 ms 18484 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 2 ms 600 KB Output is correct
38 Correct 2 ms 592 KB Output is correct
39 Correct 12 ms 1852 KB Output is correct
40 Correct 24 ms 3028 KB Output is correct
41 Correct 40 ms 4796 KB Output is correct
42 Correct 67 ms 6596 KB Output is correct
43 Correct 79 ms 8644 KB Output is correct
44 Correct 158 ms 15152 KB Output is correct
45 Correct 121 ms 12480 KB Output is correct
46 Correct 138 ms 13880 KB Output is correct
47 Correct 184 ms 17860 KB Output is correct
48 Correct 199 ms 18380 KB Output is correct
49 Correct 184 ms 18092 KB Output is correct
50 Correct 193 ms 17936 KB Output is correct
51 Correct 194 ms 18512 KB Output is correct
52 Correct 197 ms 18484 KB Output is correct
53 Correct 193 ms 18492 KB Output is correct
54 Correct 193 ms 18388 KB Output is correct
55 Correct 190 ms 18500 KB Output is correct