Submission #466365

# Submission time Handle Problem Language Result Execution time Memory
466365 2021-08-19T02:17:42 Z Namnamseo Employment (JOI16_employment) C++17
100 / 100
487 ms 12600 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define ind(x,y) lower_bound(all(x), y) - x.begin() + 1

const int M = 524288;

int tree[M<<1];
void upd(int l,int r,int v){
    l+=M; r+=M;
    while(l<=r){
        if(l%2==1) tree[l++]+=v;
        if(r%2==0) tree[r--]+=v;
        l>>=1; r>>=1;
    }
}

int get(int x){
    x+=M; int ret=0;
    while(x) ret+=tree[x], x>>=1;
    return ret;
}

vector<int> yp;

int qtype[200010];
int qx[200010];
int qy[200010];
int n, q;

int val[200010];

void treat(int pos,int dt){
    int a=val[pos], b=val[pos+1];
    a=ind(yp, a); b=ind(yp, b);
    if(a>b) upd(b+1, a, dt);
}

int main()
{
    yp.pb(0);
    scanf("%d%d",&n, &q);
    for(int i=1; i<=n; ++i){
        scanf("%d", val+i);
        yp.pb(val[i]);
    }

    for(int i=1; i<=q; ++i){
        scanf("%d", qtype+i);
        if(qtype[i] == 1){
            scanf("%d", qx+i);
        } else {
            scanf("%d", qx+i);
            scanf("%d", qy+i);
            yp.pb(qy[i]);
        }
    }

    sort(all(yp));
    yp.erase(unique(all(yp)), yp.end());

    for(int i=1; i<=n; ++i){
        treat(i, 1);
    }

    for(int i=1; i<=q; ++i){
        if(qtype[i] == 1){
            int a=ind(yp, qx[i]);
            printf("%d\n", get(a));
        } else {
            int a=qx[i], b=qy[i];
            if(1<a) treat(a-1, -1);
            treat(a, -1);
            val[a]=b;
            if(1<a) treat(a-1, 1);
            treat(a, 1);
        }
    }
    return 0;
}

Compilation message

employment.cpp: In function 'int main()':
employment.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     scanf("%d%d",&n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~
employment.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d", val+i);
      |         ~~~~~^~~~~~~~~~~~~
employment.cpp:50:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         scanf("%d", qtype+i);
      |         ~~~~~^~~~~~~~~~~~~~~
employment.cpp:52:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |             scanf("%d", qx+i);
      |             ~~~~~^~~~~~~~~~~~
employment.cpp:54:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |             scanf("%d", qx+i);
      |             ~~~~~^~~~~~~~~~~~
employment.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |             scanf("%d", qy+i);
      |             ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 452 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 448 KB Output is correct
11 Correct 3 ms 452 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 3 ms 460 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 3 ms 460 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 15 ms 1088 KB Output is correct
5 Correct 34 ms 1996 KB Output is correct
6 Correct 49 ms 2800 KB Output is correct
7 Correct 82 ms 4204 KB Output is correct
8 Correct 116 ms 5096 KB Output is correct
9 Correct 174 ms 8124 KB Output is correct
10 Correct 203 ms 7780 KB Output is correct
11 Correct 195 ms 9380 KB Output is correct
12 Correct 219 ms 10340 KB Output is correct
13 Correct 256 ms 10484 KB Output is correct
14 Correct 220 ms 10312 KB Output is correct
15 Correct 242 ms 10296 KB Output is correct
16 Correct 232 ms 10556 KB Output is correct
17 Correct 278 ms 10604 KB Output is correct
18 Correct 230 ms 10588 KB Output is correct
19 Correct 224 ms 10548 KB Output is correct
20 Correct 221 ms 10552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 428 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 452 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 3 ms 448 KB Output is correct
11 Correct 3 ms 452 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 3 ms 460 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 3 ms 460 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 15 ms 1088 KB Output is correct
20 Correct 34 ms 1996 KB Output is correct
21 Correct 49 ms 2800 KB Output is correct
22 Correct 82 ms 4204 KB Output is correct
23 Correct 116 ms 5096 KB Output is correct
24 Correct 174 ms 8124 KB Output is correct
25 Correct 203 ms 7780 KB Output is correct
26 Correct 195 ms 9380 KB Output is correct
27 Correct 219 ms 10340 KB Output is correct
28 Correct 256 ms 10484 KB Output is correct
29 Correct 220 ms 10312 KB Output is correct
30 Correct 242 ms 10296 KB Output is correct
31 Correct 232 ms 10556 KB Output is correct
32 Correct 278 ms 10604 KB Output is correct
33 Correct 230 ms 10588 KB Output is correct
34 Correct 224 ms 10548 KB Output is correct
35 Correct 221 ms 10552 KB Output is correct
36 Correct 3 ms 332 KB Output is correct
37 Correct 3 ms 460 KB Output is correct
38 Correct 5 ms 460 KB Output is correct
39 Correct 24 ms 1440 KB Output is correct
40 Correct 49 ms 2172 KB Output is correct
41 Correct 103 ms 3260 KB Output is correct
42 Correct 122 ms 4544 KB Output is correct
43 Correct 169 ms 5936 KB Output is correct
44 Correct 331 ms 10372 KB Output is correct
45 Correct 259 ms 8608 KB Output is correct
46 Correct 292 ms 9528 KB Output is correct
47 Correct 371 ms 12232 KB Output is correct
48 Correct 391 ms 12452 KB Output is correct
49 Correct 413 ms 12336 KB Output is correct
50 Correct 386 ms 12196 KB Output is correct
51 Correct 397 ms 12516 KB Output is correct
52 Correct 487 ms 12592 KB Output is correct
53 Correct 437 ms 12508 KB Output is correct
54 Correct 427 ms 12600 KB Output is correct
55 Correct 422 ms 12524 KB Output is correct