# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
55192 |
2018-07-06T09:26:55 Z |
노영훈(#1526) |
None (JOI14_ho_t5) |
C++11 |
|
444 ms |
54540 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9, XMX=200010;
int w, h, n;
struct line {
int x1, y1, x2, y2;
};
vector<line> L;
struct node {
ll sum; int l, r;
} tree[XMX*20];
int now=0;
int root0[XMX];
int rootx[XMX];
// somehow update pst
// somehow query on pst. constant x, y1~y2 (vert)
int init(int v, int s, int e, int y, int val){
if(y<s || e<y) return v;
node &nd=tree[++now];
nd=tree[v]; v=now;
nd.sum+=val;
if(s!=e){
nd.l=init(nd.l, s, (s+e)/2, y, val);
nd.r=init(nd.r, (s+e)/2+1, e, y, val);
}
return v;
}
ll sum(int v, int s, int e, int l, int r){
if(e<l || r<s) return 0;
node &nd=tree[v]; // 2-1
if(l<=s && e<=r) return nd.sum;
return sum(nd.l, s, (s+e)/2, l, r) + sum(nd.r, (s+e)/2+1, e, l, r);
}
ll vcnt=0, ecnt=0;
bool hit(line a, line b){
if(a.y1==a.y2) swap(a,b);
if(a.y1==a.y2) return false;
if(b.x1==b.x2) return false;
return (b.x1<=a.x1 && a.x1<=b.x2) && (a.y1<=b.y1 && b.y1<=a.y2);
}
int U[MX];
int find(int x){ return x==U[x] ? x : U[x]=find(U[x]); }
void unite(int x, int y){
if(find(x)==find(y)) return;
U[U[y]]=U[x];
}
int components(){
int sz=L.size();
if(sz>5000) return 1;
for(int i=0; i<sz; i++) U[i]=i;
for(int i=0; i<sz; i++)
for(int j=i+1; j<sz; j++){
if(hit(L[i], L[j])) unite(i,j);
}
set<int> S;
for(int i=0; i<sz; i++) S.insert(find(i));
// cout<<S.size()<<'\n';
return S.size();
}
vector<pii> P;
vector<line> H[XMX];
int fenwick[XMX];
void upt(int y, int val){
for(; 0<y; y-=y&(-y)) fenwick[y]+=val;
}
void upt(int l, int r, int val){
upt(r,val); upt(l-1,-val);
}
int val(int y){
int res=0;
for(; y<=w; y+=y&(-y)) res+=fenwick[y];
return res;
}
void normalize(){
// cout<<"NORM\n";
for(line &l:L){
if(l.y1==l.y2){
P.push_back({l.x1,l.y1});
P.push_back({l.x2,l.y2});
}
else{
H[l.x1].push_back(l);
}
}
sort(P.begin(), P.end());
for(int i=0, x=0; i<(int)P.size(); i++){
if(x!=P[i].first){
for(line &l:H[x]){
upt(l.y1, l.y2, -1);
}
x=P[i].first;
for(line &l:H[x]){
upt(l.y1, l.y2, 1);
}
}
int now=val(P[i].second);
if(now==0) vcnt++;
if(now!=0) ecnt--;
}
// cout<<ecnt<<' '<<vcnt<<'\n';
}
void solve(){
// cout<<"SOLVE!\n";
for(line &l:L){
if(l.y1==l.y2) continue;
int rt=rootx[l.x1];
int hit=sum(rt, 1, h, l.y1, l.y2);
ecnt+=hit;
int nowv=hit+2-sum(rt, 1, h, l.y1, l.y1)-sum(rt, 1, h, l.y2, l.y2);
vcnt+=nowv;
ecnt+=nowv-1;
// cout<<l.x1<<' '<<l.y1<<" ~ "<<l.y2<<": "<<hit<<'\n';
// cout<<ecnt<<' '<<vcnt<<'\n';
}
// cout<<ecnt<<' '<<vcnt<<'\n';
}
map<int, int> diff[XMX];
void put_horz(){
for(line &l:L){
if(l.x1==l.x2) continue;
ecnt++;
diff[l.x1][l.y1]++;
diff[l.x2+1][l.y2]--;
}
int idx=0;
for(int x=1; x<=w; x++){
for(pii p:diff[x]){
idx++;
root0[idx]=init(root0[idx-1], 1, h, p.first, p.second);
}
rootx[x]=root0[idx];
}
// for(int i=1; i<=w; i++) cout<<rootx[i]<<' ';
// cout<<'\n';
// cout<<ecnt<<' '<<vcnt<<'\n';
}
int find(int x, vector<int> &X){
return lower_bound(X.begin(), X.end(), x)-X.begin()+1;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>w>>h>>n;
vector<int> X, Y;
for(int i=1; i<=n; i++){
int x1, y1, x2, y2; cin>>x1>>y1>>x2>>y2;
L.push_back({x1,y1,x2,y2});
X.push_back(x1); X.push_back(x2);
Y.push_back(y1); Y.push_back(y2);
}
L.push_back({0,0,w,0}); L.push_back({0,h,w,h});
L.push_back({0,0,0,h}); L.push_back({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());
X.resize(unique(X.begin(), X.end())-X.begin());
sort(Y.begin(), Y.end());
Y.resize(unique(Y.begin(), Y.end())-Y.begin());
w=find(w,X); h=find(h,Y);
for(line &l:L){
l={find(l.x1,X), find(l.y1,Y), find(l.x2,X), find(l.y2,Y)};
}
put_horz();
solve();
normalize();
ll ans=ecnt-vcnt+components();
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
14456 KB |
Output is correct |
2 |
Correct |
14 ms |
14456 KB |
Output is correct |
3 |
Correct |
14 ms |
14472 KB |
Output is correct |
4 |
Correct |
14 ms |
14600 KB |
Output is correct |
5 |
Correct |
14 ms |
14600 KB |
Output is correct |
6 |
Correct |
15 ms |
14676 KB |
Output is correct |
7 |
Correct |
16 ms |
14756 KB |
Output is correct |
8 |
Correct |
23 ms |
14940 KB |
Output is correct |
9 |
Correct |
17 ms |
14988 KB |
Output is correct |
10 |
Correct |
21 ms |
15024 KB |
Output is correct |
11 |
Correct |
24 ms |
15024 KB |
Output is correct |
12 |
Correct |
19 ms |
15024 KB |
Output is correct |
13 |
Correct |
20 ms |
15024 KB |
Output is correct |
14 |
Correct |
19 ms |
15024 KB |
Output is correct |
15 |
Correct |
19 ms |
15084 KB |
Output is correct |
16 |
Correct |
14 ms |
15084 KB |
Output is correct |
17 |
Correct |
14 ms |
15084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
14456 KB |
Output is correct |
2 |
Correct |
14 ms |
14456 KB |
Output is correct |
3 |
Correct |
14 ms |
14472 KB |
Output is correct |
4 |
Correct |
14 ms |
14600 KB |
Output is correct |
5 |
Correct |
14 ms |
14600 KB |
Output is correct |
6 |
Correct |
15 ms |
14676 KB |
Output is correct |
7 |
Correct |
16 ms |
14756 KB |
Output is correct |
8 |
Correct |
23 ms |
14940 KB |
Output is correct |
9 |
Correct |
17 ms |
14988 KB |
Output is correct |
10 |
Correct |
21 ms |
15024 KB |
Output is correct |
11 |
Correct |
24 ms |
15024 KB |
Output is correct |
12 |
Correct |
19 ms |
15024 KB |
Output is correct |
13 |
Correct |
20 ms |
15024 KB |
Output is correct |
14 |
Correct |
19 ms |
15024 KB |
Output is correct |
15 |
Correct |
19 ms |
15084 KB |
Output is correct |
16 |
Correct |
14 ms |
15084 KB |
Output is correct |
17 |
Correct |
14 ms |
15084 KB |
Output is correct |
18 |
Correct |
14 ms |
15084 KB |
Output is correct |
19 |
Correct |
14 ms |
15084 KB |
Output is correct |
20 |
Correct |
15 ms |
15084 KB |
Output is correct |
21 |
Correct |
21 ms |
15084 KB |
Output is correct |
22 |
Correct |
20 ms |
15084 KB |
Output is correct |
23 |
Correct |
25 ms |
15084 KB |
Output is correct |
24 |
Correct |
20 ms |
15084 KB |
Output is correct |
25 |
Correct |
21 ms |
15084 KB |
Output is correct |
26 |
Correct |
16 ms |
15100 KB |
Output is correct |
27 |
Correct |
20 ms |
15100 KB |
Output is correct |
28 |
Correct |
19 ms |
15100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
15100 KB |
Output is correct |
2 |
Correct |
18 ms |
15100 KB |
Output is correct |
3 |
Correct |
19 ms |
15100 KB |
Output is correct |
4 |
Correct |
20 ms |
15100 KB |
Output is correct |
5 |
Incorrect |
48 ms |
18428 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
18428 KB |
Output is correct |
2 |
Correct |
19 ms |
18428 KB |
Output is correct |
3 |
Correct |
38 ms |
18428 KB |
Output is correct |
4 |
Correct |
14 ms |
18428 KB |
Output is correct |
5 |
Correct |
19 ms |
18428 KB |
Output is correct |
6 |
Correct |
444 ms |
54540 KB |
Output is correct |
7 |
Correct |
30 ms |
54540 KB |
Output is correct |
8 |
Correct |
282 ms |
54540 KB |
Output is correct |
9 |
Correct |
314 ms |
54540 KB |
Output is correct |
10 |
Correct |
332 ms |
54540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
14456 KB |
Output is correct |
2 |
Correct |
14 ms |
14456 KB |
Output is correct |
3 |
Correct |
14 ms |
14472 KB |
Output is correct |
4 |
Correct |
14 ms |
14600 KB |
Output is correct |
5 |
Correct |
14 ms |
14600 KB |
Output is correct |
6 |
Correct |
15 ms |
14676 KB |
Output is correct |
7 |
Correct |
16 ms |
14756 KB |
Output is correct |
8 |
Correct |
23 ms |
14940 KB |
Output is correct |
9 |
Correct |
17 ms |
14988 KB |
Output is correct |
10 |
Correct |
21 ms |
15024 KB |
Output is correct |
11 |
Correct |
24 ms |
15024 KB |
Output is correct |
12 |
Correct |
19 ms |
15024 KB |
Output is correct |
13 |
Correct |
20 ms |
15024 KB |
Output is correct |
14 |
Correct |
19 ms |
15024 KB |
Output is correct |
15 |
Correct |
19 ms |
15084 KB |
Output is correct |
16 |
Correct |
14 ms |
15084 KB |
Output is correct |
17 |
Correct |
14 ms |
15084 KB |
Output is correct |
18 |
Correct |
14 ms |
15084 KB |
Output is correct |
19 |
Correct |
14 ms |
15084 KB |
Output is correct |
20 |
Correct |
15 ms |
15084 KB |
Output is correct |
21 |
Correct |
21 ms |
15084 KB |
Output is correct |
22 |
Correct |
20 ms |
15084 KB |
Output is correct |
23 |
Correct |
25 ms |
15084 KB |
Output is correct |
24 |
Correct |
20 ms |
15084 KB |
Output is correct |
25 |
Correct |
21 ms |
15084 KB |
Output is correct |
26 |
Correct |
16 ms |
15100 KB |
Output is correct |
27 |
Correct |
20 ms |
15100 KB |
Output is correct |
28 |
Correct |
19 ms |
15100 KB |
Output is correct |
29 |
Correct |
20 ms |
15100 KB |
Output is correct |
30 |
Correct |
18 ms |
15100 KB |
Output is correct |
31 |
Correct |
19 ms |
15100 KB |
Output is correct |
32 |
Correct |
20 ms |
15100 KB |
Output is correct |
33 |
Incorrect |
48 ms |
18428 KB |
Output isn't correct |
34 |
Halted |
0 ms |
0 KB |
- |