Submission #257345

# Submission time Handle Problem Language Result Execution time Memory
257345 2020-08-04T06:38:05 Z 문홍윤(#5062) None (JOI16_worst_reporter2) C++17
100 / 100
403 ms 36612 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
const int inf=1e8;

struct LAZY_SEGMENT_TREE{
    int x;
    struct NODE{
        int st, fin;
        int minn, lazy;
    }tree[1600000];
    void init(int point, int num){
        if(num==1)tree[point].st=tree[point].fin=++x;
        if(num<=1)return;
        init(point*2, num-num/2);
        init(point*2+1, num/2);
        tree[point].st=tree[point*2].st;
        tree[point].fin=tree[point*2+1].fin;
    }
    void eat(int point){
        tree[point].minn=min(tree[point*2].minn+tree[point*2].lazy, tree[point*2+1].minn+tree[point*2+1].lazy);
    }
    void propogate(int point){
        if(tree[point].st==tree[point].fin){
            tree[point].minn+=tree[point].lazy;
            tree[point].lazy=0;
            return;
        }
        tree[point].minn+=tree[point].lazy;
        tree[point*2].lazy+=tree[point].lazy;
        tree[point*2+1].lazy+=tree[point].lazy;
        tree[point].lazy=0;
    }
    void alter(int point, int a, int b, LL qu){
        if(tree[point].st>=a&&tree[point].fin<=b){
            tree[point].lazy+=qu;
            return;
        }
        if(tree[point].st>b||tree[point].fin<a)return;
        propogate(point);
        alter(point*2, a, b, qu);
        alter(point*2+1, a, b, qu);
        eat(point);
    }
    int query(int point, int a, int b){
        if(tree[point].st>=a&&tree[point].fin<=b)return tree[point].minn+tree[point].lazy;
        if(tree[point].st>b||tree[point].fin<a)return inf;
        propogate(point);
        int ret=min(query(point*2, a, b), query(point*2+1, a, b));
        eat(point);
        return ret;
    }
    void init(int num){init(1, num);}
    void alter(int a, int b, int qu){alter(1, a, b, qu);}
    int query(int a, int b){return query(1, a, b);}
}seg;

int n, ans;
int arra[200010], xa[200010];
int arrb[200010], xb[200010];
vector<int> id, stk[200010];

int main(){
    scanf("%d", &n);
    seg.init(2*n);
    for(int i=1; i<=n; i++){
        scanf("%d %d", &arra[i], &xa[i]);
        xa[i]*=2;
        id.eb(xa[i]);
    }
    for(int i=1; i<=n; i++){
        scanf("%d %d", &arrb[i], &xb[i]);
        xb[i]*=2;
        xb[i]++;
        id.eb(xb[i]);
    }
    reverse(arra+1, arra+n+1);
    reverse(arrb+1, arrb+n+1);
    reverse(xa+1, xa+n+1);
    reverse(xb+1, xb+n+1);
    svec(id); press(id);
    for(int i=1; i<=n; i++){
        xa[i]=lb(id, xa[i])-id.begin()+1;
        xb[i]=lb(id, xb[i])-id.begin()+1;
        seg.alter(xa[i], xb[i]-1, 1);
    }
    int pv=1;
    ans=n;
    for(int i=1; i<=n; i++){
        for(; pv<=n; pv++){
            if(xa[pv]>xb[i])break;
            stk[arra[pv]].eb(xa[pv]);
        }
        if(stk[arrb[i]].size()==0)continue;
        if(seg.query(stk[arrb[i]].back(), xb[i]-1)>=1){
            seg.alter(stk[arrb[i]].back(), xb[i]-1, -1);
            stk[arrb[i]].pop_back();
            ans--;
        }
    }
    printf("%d", ans);
}


/*
3
3 500
2 200
1 100
1 1000
3 700
3 400

3
3 3
3 2
1 1
3 4
3 2
1 1


6
1 70
4 50
1 30
2 20
1 10
3 0
6 100
2 90
1 80
2 60
4 40
1 10
*/

Compilation message

worst_reporter2.cpp: In function 'int main()':
worst_reporter2.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
worst_reporter2.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &arra[i], &xa[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
worst_reporter2.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &arrb[i], &xb[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 3 ms 4992 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
20 Correct 3 ms 4992 KB Output is correct
21 Correct 3 ms 4992 KB Output is correct
22 Correct 4 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 3 ms 4992 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
20 Correct 3 ms 4992 KB Output is correct
21 Correct 3 ms 4992 KB Output is correct
22 Correct 4 ms 4992 KB Output is correct
23 Correct 10 ms 5888 KB Output is correct
24 Correct 12 ms 6016 KB Output is correct
25 Correct 9 ms 5888 KB Output is correct
26 Correct 9 ms 5888 KB Output is correct
27 Correct 10 ms 5888 KB Output is correct
28 Correct 11 ms 5760 KB Output is correct
29 Correct 11 ms 5760 KB Output is correct
30 Correct 11 ms 5760 KB Output is correct
31 Correct 11 ms 5760 KB Output is correct
32 Correct 13 ms 5888 KB Output is correct
33 Correct 10 ms 5760 KB Output is correct
34 Correct 11 ms 5888 KB Output is correct
35 Correct 10 ms 5760 KB Output is correct
36 Correct 9 ms 5760 KB Output is correct
37 Correct 13 ms 5760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 3 ms 4992 KB Output is correct
6 Correct 4 ms 4992 KB Output is correct
7 Correct 4 ms 4992 KB Output is correct
8 Correct 3 ms 4992 KB Output is correct
9 Correct 3 ms 4992 KB Output is correct
10 Correct 4 ms 4992 KB Output is correct
11 Correct 3 ms 4992 KB Output is correct
12 Correct 6 ms 4992 KB Output is correct
13 Correct 4 ms 4992 KB Output is correct
14 Correct 4 ms 4992 KB Output is correct
15 Correct 4 ms 4992 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 4 ms 4992 KB Output is correct
18 Correct 3 ms 4992 KB Output is correct
19 Correct 3 ms 4992 KB Output is correct
20 Correct 3 ms 4992 KB Output is correct
21 Correct 3 ms 4992 KB Output is correct
22 Correct 4 ms 4992 KB Output is correct
23 Correct 10 ms 5888 KB Output is correct
24 Correct 12 ms 6016 KB Output is correct
25 Correct 9 ms 5888 KB Output is correct
26 Correct 9 ms 5888 KB Output is correct
27 Correct 10 ms 5888 KB Output is correct
28 Correct 11 ms 5760 KB Output is correct
29 Correct 11 ms 5760 KB Output is correct
30 Correct 11 ms 5760 KB Output is correct
31 Correct 11 ms 5760 KB Output is correct
32 Correct 13 ms 5888 KB Output is correct
33 Correct 10 ms 5760 KB Output is correct
34 Correct 11 ms 5888 KB Output is correct
35 Correct 10 ms 5760 KB Output is correct
36 Correct 9 ms 5760 KB Output is correct
37 Correct 13 ms 5760 KB Output is correct
38 Correct 353 ms 36612 KB Output is correct
39 Correct 370 ms 35300 KB Output is correct
40 Correct 333 ms 35428 KB Output is correct
41 Correct 327 ms 35428 KB Output is correct
42 Correct 390 ms 35300 KB Output is correct
43 Correct 343 ms 30820 KB Output is correct
44 Correct 348 ms 30820 KB Output is correct
45 Correct 346 ms 30948 KB Output is correct
46 Correct 296 ms 31464 KB Output is correct
47 Correct 403 ms 32576 KB Output is correct
48 Correct 355 ms 30444 KB Output is correct
49 Correct 402 ms 30052 KB Output is correct
50 Correct 338 ms 30180 KB Output is correct
51 Correct 274 ms 30948 KB Output is correct
52 Correct 371 ms 30828 KB Output is correct