Submission #96425

# Submission time Handle Problem Language Result Execution time Memory
96425 2019-02-09T12:14:40 Z easrui None (JOI14_ho_t5) C++14
100 / 100
302 ms 14432 KB
#include <bits/stdc++.h>
#define sz first
#define col second
using namespace std;
const int MN = 1e5+9;
typedef pair<int,int> pii;
struct line{
    int A,B,C,D;
    line(){};
    line(int a, int b, int c, int d){
        A = a, B = b , C = c, D = d;
    }
} L[MN];

struct event{
    int s,e,t,v;
    event(){};
    event(int a, int b, int c, int d){
        s = a, e = b, t = c, v = d;
    }
    bool operator < (const event &A) const{
        if(t==A.t) return A.v<v;
        return t<A.t;
    }
} E[2*MN];

int W,H,N,A,B,C,D,par[MN],cnt,comp,nume;
long long inter;
bool ch[MN];
pii T[8*MN];
vector<int> X,Y;

int fnd(int a)
{
    return par[a]==a ? a : par[a] = fnd(par[a]);
}

void join(int a, int b)
{
    if(a==0 || b==0) return;
    a = fnd(a), b = fnd(b);
    if(a!=b) par[b] = a;
}

void upt(int x, int v, int s, int e, int pos)
{
    if(x<s || x>e) return;
    int c = T[pos].col;
    if(c){
        if(s!=e){
            if(T[2*pos].sz) join(T[2*pos].col,c);
            if(T[2*pos+1].sz) join(T[2*pos+1].col,c);
     		T[2*pos].col = c;
        	T[2*pos+1].col = c;
        }
        T[pos].col = 0;
    }
    if(s==e){
      	if(v==-1 && !c) comp++;
        T[pos].sz += v;
        return;
    }
    int m = (s+e)/2;
    upt(x,v,s,m,2*pos);
    upt(x,v,m+1,e,2*pos+1);
    T[pos].sz = T[2*pos].sz + T[2*pos+1].sz;
}

int act(int l, int r, int s, int e, int pos)
{
    if(r<s || l>e) return 0;
    int c = T[pos].col;
    if(c){
        if(s!=e){
            if(T[2*pos].sz) join(T[2*pos].col,c);
            if(T[2*pos+1].sz) join(T[2*pos+1].col,c);
     		T[2*pos].col = c;
        	T[2*pos+1].col = c;
        	T[pos].col = 0;
        }
    }
    if(l<=s && e<=r){
        if(T[pos].sz) join(c,cnt);
        T[pos].col = cnt;
        return T[pos].sz;
    }
    int m = (s+e)/2;
    return act(l,r,s,m,2*pos)+act(l,r,m+1,e,2*pos+1);
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    //freopen("input.txt","r",stdin);
    cin >> W >> H >> N;
    for(int i=0; i<N; i++){
        cin >> A >> B >> C >> D;
        if(A>C) swap(A,C);
        if(B>D) swap(B,D);
        L[i] = line(A,B,C,D);
        X.push_back(A);
        X.push_back(C);
        Y.push_back(B);
        Y.push_back(D);
    }
    L[N] = line(0,0,0,H);
    L[N+1] = line(0,0,W,0);
    L[N+2] = line(0,H,W,H);
    L[N+3] = line(W,0,W,H);
    X.push_back(0);
    X.push_back(W);
    Y.push_back(0);
    Y.push_back(H);
    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());
    X.erase(unique(X.begin(),X.end()),X.end());
    Y.erase(unique(Y.begin(),Y.end()),Y.end());
    nume = N+4;
    for(int i=0; i<N+4; i++){
        L[i].A = lower_bound(X.begin(),X.end(),L[i].A)-X.begin();
        L[i].C = lower_bound(X.begin(),X.end(),L[i].C)-X.begin();
        L[i].B = lower_bound(Y.begin(),Y.end(),L[i].B)-Y.begin();
        L[i].D = lower_bound(Y.begin(),Y.end(),L[i].D)-Y.begin();
        if(L[i].C!=L[i].A){
            E[i] = event(L[i].B,L[i].D,L[i].A,1);
            E[nume++] = event(L[i].B,L[i].D,L[i].C,-1);
        } else E[i] = event(L[i].B,L[i].D,L[i].C,0);
    }
    sort(E,E+nume);
    for(int i=0; i<nume; i++){
        if(E[i].v) upt(E[i].s,E[i].v,0,Y.size()-1,1);
        else{
            cnt++;
            par[cnt] = cnt;
            inter += act(E[i].s,E[i].e,0,Y.size()-1,1);
        }
    }
    for(int i=1; i<=cnt; i++) ch[fnd(i)] = true;
    for(int i=1; i<=cnt; i++) comp += ch[i];
    cout << inter+comp-N-4;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 424 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 424 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 508 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 3 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 19 ms 1656 KB Output is correct
6 Correct 99 ms 7472 KB Output is correct
7 Correct 198 ms 14276 KB Output is correct
8 Correct 214 ms 14304 KB Output is correct
9 Correct 214 ms 14304 KB Output is correct
10 Correct 189 ms 14332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 552 KB Output is correct
3 Correct 21 ms 1676 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 266 ms 14188 KB Output is correct
7 Correct 12 ms 1528 KB Output is correct
8 Correct 125 ms 10468 KB Output is correct
9 Correct 186 ms 10464 KB Output is correct
10 Correct 163 ms 10468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 424 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 1 ms 504 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 508 KB Output is correct
23 Correct 4 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 4 ms 504 KB Output is correct
28 Correct 3 ms 548 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 504 KB Output is correct
31 Correct 2 ms 380 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 19 ms 1656 KB Output is correct
34 Correct 99 ms 7472 KB Output is correct
35 Correct 198 ms 14276 KB Output is correct
36 Correct 214 ms 14304 KB Output is correct
37 Correct 214 ms 14304 KB Output is correct
38 Correct 189 ms 14332 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 3 ms 552 KB Output is correct
41 Correct 21 ms 1676 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 4 ms 504 KB Output is correct
44 Correct 266 ms 14188 KB Output is correct
45 Correct 12 ms 1528 KB Output is correct
46 Correct 125 ms 10468 KB Output is correct
47 Correct 186 ms 10464 KB Output is correct
48 Correct 163 ms 10468 KB Output is correct
49 Correct 3 ms 508 KB Output is correct
50 Correct 3 ms 504 KB Output is correct
51 Correct 3 ms 504 KB Output is correct
52 Correct 120 ms 7444 KB Output is correct
53 Correct 98 ms 7404 KB Output is correct
54 Correct 135 ms 7480 KB Output is correct
55 Correct 302 ms 14308 KB Output is correct
56 Correct 203 ms 14232 KB Output is correct
57 Correct 265 ms 14432 KB Output is correct
58 Correct 269 ms 14304 KB Output is correct
59 Correct 142 ms 10468 KB Output is correct
60 Correct 154 ms 10464 KB Output is correct
61 Correct 168 ms 10440 KB Output is correct
62 Correct 171 ms 10592 KB Output is correct
63 Correct 264 ms 14176 KB Output is correct
64 Correct 191 ms 14284 KB Output is correct
65 Correct 260 ms 14224 KB Output is correct
66 Correct 264 ms 14304 KB Output is correct
67 Correct 243 ms 14432 KB Output is correct
68 Correct 240 ms 14296 KB Output is correct
69 Correct 239 ms 14176 KB Output is correct
70 Correct 237 ms 14276 KB Output is correct
71 Correct 130 ms 8160 KB Output is correct
72 Correct 189 ms 11388 KB Output is correct