답안 #576117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576117 2022-06-12T11:12:28 Z urd05 Employment (JOI16_employment) C++17
100 / 100
305 ms 14888 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;
typedef pair<P,int> Pi;
int val[200001];
P a[200002];
int n,m;
vector<Pi> query;
vector<int> pr;
const int sz=524288;
int seg[sz*2];

int sum(int l,int r,int node=1,int nodel=0,int noder=sz-1) {
    if (r<nodel||l>noder) {
        return 0;
    }
    if (l<=nodel&&noder<=r) {
        return seg[node];
    }
    int mid=(nodel+noder)/2;
    return sum(l,r,node*2,nodel,mid)+sum(l,r,node*2+1,mid+1,noder);
}

void update(int i,int x) {
    i+=sz;
    seg[i]+=x;
    while (i>1) {
        i/=2;
        seg[i]=seg[i*2]+seg[i*2+1];
    }
}

int main() {
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++) {
        scanf("%d",&a[i].first);
        a[i].second=i;
        pr.push_back(a[i].first);
    }
    for(int i=0;i<m;i++) {
        int t;
        scanf("%d",&t);
        if (t==1) {
            int b;
            scanf("%d",&b);
            query.push_back(Pi(P(t,b),-1));
        }
        else {
            int c,d;
            scanf("%d %d",&c,&d);
            pr.push_back(d);
            query.push_back(Pi(P(t,c),d));
        }
    }
    sort(pr.begin(),pr.end());
    pr.erase(unique(pr.begin(),pr.end()),pr.end());
    for(int i=1;i<=n;i++) {
        val[i]=1;
        if (a[i-1]>a[i]) {
            val[i]--;
        }
        if (a[i+1]>a[i]) {
            val[i]--;
        }
        int ind=lower_bound(pr.begin(),pr.end(),a[i].first)-pr.begin();
        update(ind,val[i]);
    }
    for(int i=0;i<m;i++) {
        if (query[i].first.first==1) {
            int b=query[i].first.second;
            int ind=lower_bound(pr.begin(),pr.end(),b)-pr.begin();
            printf("%d\n",sum(ind,sz-1));
        }
        else {
            int c=query[i].first.second;
            int d=query[i].second;
            int ind=lower_bound(pr.begin(),pr.end(),a[c].first)-pr.begin();
            update(ind,-val[c]);
            int temp[3];
            memset(temp,0,sizeof(temp));
            if (a[c-1]<a[c]) {
                temp[0]++;
            }
            if (a[c]>a[c+1]) {
                temp[2]++;
            }
            a[c]=P(d,c);
            temp[1]=1;
            if (a[c-1]<a[c]) {
                temp[0]--;
            }
            else {
                temp[1]--;
            }
            if (a[c]<a[c+1]) {
                temp[1]--;
            }
            else {
                temp[2]--;
            }
            if (c!=1) {
                int ind0=lower_bound(pr.begin(),pr.end(),a[c-1].first)-pr.begin();
                update(ind0,temp[0]);
                val[c-1]+=temp[0];
            }
            int ind1=lower_bound(pr.begin(),pr.end(),a[c].first)-pr.begin();
            update(ind1,temp[1]);
            val[c]=temp[1];
            if (c!=n) {
                int ind2=lower_bound(pr.begin(),pr.end(),a[c+1].first)-pr.begin();
                update(ind2,temp[2]);
                val[c+1]+=temp[2];
            }
        }
    }
    return 0;
}

Compilation message

employment.cpp: In function 'int main()':
employment.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
employment.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%d",&a[i].first);
      |         ~~~~~^~~~~~~~~~~~~~~~~~
employment.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%d",&t);
      |         ~~~~~^~~~~~~~~
employment.cpp:46:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |             scanf("%d",&b);
      |             ~~~~~^~~~~~~~~
employment.cpp:51:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |             scanf("%d %d",&c,&d);
      |             ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 456 KB Output is correct
10 Correct 4 ms 456 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 3 ms 516 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 3 ms 464 KB Output is correct
3 Correct 4 ms 460 KB Output is correct
4 Correct 13 ms 1512 KB Output is correct
5 Correct 27 ms 2384 KB Output is correct
6 Correct 43 ms 3320 KB Output is correct
7 Correct 82 ms 5340 KB Output is correct
8 Correct 83 ms 6460 KB Output is correct
9 Correct 142 ms 10012 KB Output is correct
10 Correct 134 ms 10368 KB Output is correct
11 Correct 167 ms 12092 KB Output is correct
12 Correct 174 ms 13276 KB Output is correct
13 Correct 175 ms 13360 KB Output is correct
14 Correct 180 ms 13104 KB Output is correct
15 Correct 197 ms 13288 KB Output is correct
16 Correct 197 ms 13604 KB Output is correct
17 Correct 213 ms 13488 KB Output is correct
18 Correct 182 ms 13724 KB Output is correct
19 Correct 192 ms 13512 KB Output is correct
20 Correct 192 ms 13592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 456 KB Output is correct
10 Correct 4 ms 456 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 3 ms 516 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 3 ms 464 KB Output is correct
18 Correct 4 ms 460 KB Output is correct
19 Correct 13 ms 1512 KB Output is correct
20 Correct 27 ms 2384 KB Output is correct
21 Correct 43 ms 3320 KB Output is correct
22 Correct 82 ms 5340 KB Output is correct
23 Correct 83 ms 6460 KB Output is correct
24 Correct 142 ms 10012 KB Output is correct
25 Correct 134 ms 10368 KB Output is correct
26 Correct 167 ms 12092 KB Output is correct
27 Correct 174 ms 13276 KB Output is correct
28 Correct 175 ms 13360 KB Output is correct
29 Correct 180 ms 13104 KB Output is correct
30 Correct 197 ms 13288 KB Output is correct
31 Correct 197 ms 13604 KB Output is correct
32 Correct 213 ms 13488 KB Output is correct
33 Correct 182 ms 13724 KB Output is correct
34 Correct 192 ms 13512 KB Output is correct
35 Correct 192 ms 13592 KB Output is correct
36 Correct 3 ms 468 KB Output is correct
37 Correct 3 ms 424 KB Output is correct
38 Correct 3 ms 468 KB Output is correct
39 Correct 18 ms 1580 KB Output is correct
40 Correct 34 ms 2348 KB Output is correct
41 Correct 70 ms 3648 KB Output is correct
42 Correct 78 ms 5360 KB Output is correct
43 Correct 108 ms 6832 KB Output is correct
44 Correct 218 ms 12540 KB Output is correct
45 Correct 170 ms 10344 KB Output is correct
46 Correct 187 ms 11344 KB Output is correct
47 Correct 260 ms 14472 KB Output is correct
48 Correct 279 ms 14564 KB Output is correct
49 Correct 289 ms 14516 KB Output is correct
50 Correct 273 ms 14328 KB Output is correct
51 Correct 249 ms 14708 KB Output is correct
52 Correct 305 ms 14764 KB Output is correct
53 Correct 256 ms 14888 KB Output is correct
54 Correct 274 ms 14740 KB Output is correct
55 Correct 261 ms 14840 KB Output is correct