답안 #55418

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55418 2018-07-07T08:53:41 Z 내가진짜뚜룹뚭스(#2073) Employment (JOI16_employment) C++11
100 / 100
377 ms 8096 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

struct idxtree {
    int tree[1050000];
    int key = 524288;
    void upd(int s, int e, int val) {
        s += key; e += key;
        while(s<=e) {
            if (s&1) tree[s++] += val;
            if (~e&1) tree[e--] += val;
            s/=2;e/=2;
        }
    }
    int getv(int idx) {
        idx += key;
        int ans = 0;
        while(idx>0) {
            ans += tree[idx];
            idx/=2;
        }
        return ans;
    }
} it;

struct query {
    int t, a, b;
    query(){}
    query(int t, int a, int b):t(t),a(a),b(b){}
};

int n, m;
int arr[200100];
query que[200100];
vector<int> comp;

int main() {
    int i;

    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++) {
        scanf("%d",&arr[i]);
        comp.push_back(arr[i]);
    }
    arr[0] = 0;
    arr[n+1] = 0;
    n+=2;
    comp.push_back(0);
    for (i=0;i<m;i++) {
        int t, a, b = -1;
        scanf("%d",&t);
        if (t==1) {
            scanf("%d",&a);
        }
        else {
            scanf("%d%d",&a,&b);
        }
        if (b>0) comp.push_back(b);
        que[i] = query(t,a,b);
    }
    sort(comp.begin(),comp.end());
    comp.erase(unique(comp.begin(),comp.end()),comp.end());
    for (i=0;i<n;i++) {
        arr[i] = lower_bound(comp.begin(),comp.end(),arr[i])-comp.begin();
    }
    for (i=0;i<m;i++) {
        if (que[i].t==2) que[i].b = lower_bound(comp.begin(),comp.end(),que[i].b)-comp.begin();
        if (que[i].t==1) que[i].a = lower_bound(comp.begin(),comp.end(),que[i].a)-comp.begin();
    }
    for (i=0;i+1<n;i++) {
        if (arr[i]<arr[i+1]) it.upd(arr[i]+1,arr[i+1],1);
    }
    for (i=0;i<m;i++) {
        if (que[i].t==1) {
            printf("%d\n",it.getv(que[i].a));
        }
        else {
            if (arr[que[i].a-1]<arr[que[i].a]) it.upd(arr[que[i].a-1]+1,arr[que[i].a],-1);
            if (arr[que[i].a]<arr[que[i].a+1]) it.upd(arr[que[i].a]+1,arr[que[i].a+1],-1);
            arr[que[i].a] = que[i].b;
            if (arr[que[i].a-1]<arr[que[i].a]) it.upd(arr[que[i].a-1]+1,arr[que[i].a],+1);
            if (arr[que[i].a]<arr[que[i].a+1]) it.upd(arr[que[i].a]+1,arr[que[i].a+1],+1);
        }
    }

    return 0;
}

Compilation message

employment.cpp: In function 'int main()':
employment.cpp:44: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:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&arr[i]);
         ~~~~~^~~~~~~~~~~~~~
employment.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&t);
         ~~~~~^~~~~~~~~
employment.cpp:57:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&a);
             ~~~~~^~~~~~~~~
employment.cpp:60:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d",&a,&b);
             ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 4 ms 488 KB Output is correct
5 Correct 6 ms 648 KB Output is correct
6 Correct 3 ms 676 KB Output is correct
7 Correct 4 ms 676 KB Output is correct
8 Correct 3 ms 676 KB Output is correct
9 Correct 5 ms 676 KB Output is correct
10 Correct 5 ms 724 KB Output is correct
11 Correct 6 ms 748 KB Output is correct
12 Correct 5 ms 748 KB Output is correct
13 Correct 4 ms 864 KB Output is correct
14 Correct 6 ms 864 KB Output is correct
15 Correct 5 ms 864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 864 KB Output is correct
2 Correct 5 ms 864 KB Output is correct
3 Correct 4 ms 864 KB Output is correct
4 Correct 20 ms 1180 KB Output is correct
5 Correct 33 ms 1832 KB Output is correct
6 Correct 55 ms 2388 KB Output is correct
7 Correct 92 ms 3252 KB Output is correct
8 Correct 97 ms 3920 KB Output is correct
9 Correct 174 ms 5952 KB Output is correct
10 Correct 158 ms 5952 KB Output is correct
11 Correct 208 ms 6704 KB Output is correct
12 Correct 224 ms 7344 KB Output is correct
13 Correct 252 ms 7472 KB Output is correct
14 Correct 219 ms 7472 KB Output is correct
15 Correct 227 ms 7472 KB Output is correct
16 Correct 268 ms 7488 KB Output is correct
17 Correct 232 ms 7488 KB Output is correct
18 Correct 277 ms 7620 KB Output is correct
19 Correct 281 ms 7620 KB Output is correct
20 Correct 315 ms 7620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 428 KB Output is correct
4 Correct 4 ms 488 KB Output is correct
5 Correct 6 ms 648 KB Output is correct
6 Correct 3 ms 676 KB Output is correct
7 Correct 4 ms 676 KB Output is correct
8 Correct 3 ms 676 KB Output is correct
9 Correct 5 ms 676 KB Output is correct
10 Correct 5 ms 724 KB Output is correct
11 Correct 6 ms 748 KB Output is correct
12 Correct 5 ms 748 KB Output is correct
13 Correct 4 ms 864 KB Output is correct
14 Correct 6 ms 864 KB Output is correct
15 Correct 5 ms 864 KB Output is correct
16 Correct 3 ms 864 KB Output is correct
17 Correct 5 ms 864 KB Output is correct
18 Correct 4 ms 864 KB Output is correct
19 Correct 20 ms 1180 KB Output is correct
20 Correct 33 ms 1832 KB Output is correct
21 Correct 55 ms 2388 KB Output is correct
22 Correct 92 ms 3252 KB Output is correct
23 Correct 97 ms 3920 KB Output is correct
24 Correct 174 ms 5952 KB Output is correct
25 Correct 158 ms 5952 KB Output is correct
26 Correct 208 ms 6704 KB Output is correct
27 Correct 224 ms 7344 KB Output is correct
28 Correct 252 ms 7472 KB Output is correct
29 Correct 219 ms 7472 KB Output is correct
30 Correct 227 ms 7472 KB Output is correct
31 Correct 268 ms 7488 KB Output is correct
32 Correct 232 ms 7488 KB Output is correct
33 Correct 277 ms 7620 KB Output is correct
34 Correct 281 ms 7620 KB Output is correct
35 Correct 315 ms 7620 KB Output is correct
36 Correct 3 ms 7620 KB Output is correct
37 Correct 4 ms 7620 KB Output is correct
38 Correct 9 ms 7620 KB Output is correct
39 Correct 21 ms 7620 KB Output is correct
40 Correct 45 ms 7620 KB Output is correct
41 Correct 61 ms 7620 KB Output is correct
42 Correct 92 ms 7620 KB Output is correct
43 Correct 133 ms 7620 KB Output is correct
44 Correct 273 ms 7620 KB Output is correct
45 Correct 225 ms 7620 KB Output is correct
46 Correct 260 ms 7620 KB Output is correct
47 Correct 348 ms 8000 KB Output is correct
48 Correct 314 ms 8000 KB Output is correct
49 Correct 318 ms 8000 KB Output is correct
50 Correct 351 ms 8000 KB Output is correct
51 Correct 333 ms 8096 KB Output is correct
52 Correct 305 ms 8096 KB Output is correct
53 Correct 326 ms 8096 KB Output is correct
54 Correct 348 ms 8096 KB Output is correct
55 Correct 377 ms 8096 KB Output is correct