Submission #55407

# Submission time Handle Problem Language Result Execution time Memory
55407 2018-07-07T08:01:46 Z 뚜룹뚭스(#2071) Employment (JOI16_employment) C++11
100 / 100
653 ms 9912 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

int idx[1050000];
int bp;

void add(int x, int y, int v)
{
    if(y < x)
        return;
    x += bp;
    y += bp;
    while(x < y)
    {
        if(x % 2 == 1)
            idx[x++] += v;
        if(y % 2 == 0)
            idx[y--] += v;
        x /= 2;
        y /= 2;
    }
    if(x == y)
        idx[x] += v;
}

int sum(int x)
{
    int r = 0;
    x += bp;
    while(x)
    {
        r += idx[x];
        x /= 2;
    }
    return r;
}

int arr[200010];
int que[200010][3];

vector<int> com;
inline int cnv(int x)
{
    return lower_bound(com.begin(), com.end(), x) - com.begin();
}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, m, i, j;
    scanf("%d%d", &n, &m);
    for(i = 1; i <= n; i++)
        scanf("%d", &arr[i]);
    for(i = 0; i < m; i++)
    {
        for(j = 0; j < 2; j++)
            scanf("%d", &que[i][j]);
        if(que[i][0] == 2)
            scanf("%d", &que[i][2]);
    }

    for(i = 0; i <= n; i++)
        com.push_back(arr[i]);
    for(i = 0; i < m; i++)
    {
        if(que[i][0] == 1)
            com.push_back(que[i][1]);
        else
            com.push_back(que[i][2]);
    }

    sort(com.begin(), com.end());
    com.erase(unique(com.begin(), com.end()), com.end());

    for(bp = 1; bp < com.size(); bp *= 2);

    for(i = 0; i < n; i++)
        add(cnv(arr[i]) + 1, cnv(arr[i + 1]), 1);

    for(i = 0; i < m; i++)
    {
        if(que[i][0] == 1)
        {
            int r = sum(cnv(que[i][1]));
            printf("%d\n", r);
        }
        else
        {
            int x = que[i][1];

            add(cnv(arr[x - 1]) + 1, cnv(arr[x]), -1);
            add(cnv(arr[x]) + 1, cnv(arr[x + 1]), -1);

            arr[x] = que[i][2];

            add(cnv(arr[x - 1]) + 1, cnv(arr[x]), 1);
            add(cnv(arr[x]) + 1, cnv(arr[x + 1]), 1);
        }
    }
    return 0;
}

Compilation message

employment.cpp: In function 'int main()':
employment.cpp:93:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(bp = 1; bp < com.size(); bp *= 2);
                 ~~~^~~~~~~~~~~~
employment.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
employment.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~
employment.cpp:75:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &que[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~
employment.cpp:77:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &que[i][2]);
             ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 4 ms 472 KB Output is correct
5 Correct 4 ms 672 KB Output is correct
6 Correct 3 ms 672 KB Output is correct
7 Correct 5 ms 672 KB Output is correct
8 Correct 5 ms 672 KB Output is correct
9 Correct 5 ms 700 KB Output is correct
10 Correct 5 ms 700 KB Output is correct
11 Correct 6 ms 700 KB Output is correct
12 Correct 6 ms 720 KB Output is correct
13 Correct 7 ms 720 KB Output is correct
14 Correct 5 ms 764 KB Output is correct
15 Correct 7 ms 764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 764 KB Output is correct
2 Correct 6 ms 764 KB Output is correct
3 Correct 4 ms 780 KB Output is correct
4 Correct 21 ms 1436 KB Output is correct
5 Correct 49 ms 2216 KB Output is correct
6 Correct 82 ms 3136 KB Output is correct
7 Correct 137 ms 4172 KB Output is correct
8 Correct 133 ms 5096 KB Output is correct
9 Correct 292 ms 8060 KB Output is correct
10 Correct 218 ms 8060 KB Output is correct
11 Correct 323 ms 8900 KB Output is correct
12 Correct 377 ms 9728 KB Output is correct
13 Correct 356 ms 9728 KB Output is correct
14 Correct 344 ms 9728 KB Output is correct
15 Correct 351 ms 9728 KB Output is correct
16 Correct 366 ms 9760 KB Output is correct
17 Correct 382 ms 9768 KB Output is correct
18 Correct 392 ms 9912 KB Output is correct
19 Correct 349 ms 9912 KB Output is correct
20 Correct 387 ms 9912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 4 ms 472 KB Output is correct
5 Correct 4 ms 672 KB Output is correct
6 Correct 3 ms 672 KB Output is correct
7 Correct 5 ms 672 KB Output is correct
8 Correct 5 ms 672 KB Output is correct
9 Correct 5 ms 700 KB Output is correct
10 Correct 5 ms 700 KB Output is correct
11 Correct 6 ms 700 KB Output is correct
12 Correct 6 ms 720 KB Output is correct
13 Correct 7 ms 720 KB Output is correct
14 Correct 5 ms 764 KB Output is correct
15 Correct 7 ms 764 KB Output is correct
16 Correct 3 ms 764 KB Output is correct
17 Correct 6 ms 764 KB Output is correct
18 Correct 4 ms 780 KB Output is correct
19 Correct 21 ms 1436 KB Output is correct
20 Correct 49 ms 2216 KB Output is correct
21 Correct 82 ms 3136 KB Output is correct
22 Correct 137 ms 4172 KB Output is correct
23 Correct 133 ms 5096 KB Output is correct
24 Correct 292 ms 8060 KB Output is correct
25 Correct 218 ms 8060 KB Output is correct
26 Correct 323 ms 8900 KB Output is correct
27 Correct 377 ms 9728 KB Output is correct
28 Correct 356 ms 9728 KB Output is correct
29 Correct 344 ms 9728 KB Output is correct
30 Correct 351 ms 9728 KB Output is correct
31 Correct 366 ms 9760 KB Output is correct
32 Correct 382 ms 9768 KB Output is correct
33 Correct 392 ms 9912 KB Output is correct
34 Correct 349 ms 9912 KB Output is correct
35 Correct 387 ms 9912 KB Output is correct
36 Correct 4 ms 9912 KB Output is correct
37 Correct 6 ms 9912 KB Output is correct
38 Correct 8 ms 9912 KB Output is correct
39 Correct 43 ms 9912 KB Output is correct
40 Correct 84 ms 9912 KB Output is correct
41 Correct 173 ms 9912 KB Output is correct
42 Correct 185 ms 9912 KB Output is correct
43 Correct 242 ms 9912 KB Output is correct
44 Correct 456 ms 9912 KB Output is correct
45 Correct 366 ms 9912 KB Output is correct
46 Correct 412 ms 9912 KB Output is correct
47 Correct 466 ms 9912 KB Output is correct
48 Correct 507 ms 9912 KB Output is correct
49 Correct 540 ms 9912 KB Output is correct
50 Correct 509 ms 9912 KB Output is correct
51 Correct 503 ms 9912 KB Output is correct
52 Correct 589 ms 9912 KB Output is correct
53 Correct 653 ms 9912 KB Output is correct
54 Correct 533 ms 9912 KB Output is correct
55 Correct 541 ms 9912 KB Output is correct