# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
204493 |
2020-02-26T05:13:07 Z |
gs18115 |
None (JOI14_ho_t5) |
C++14 |
|
362 ms |
24576 KB |
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
struct dsu
{
int pa[100020];
dsu(){}
inline void init()
{
fill(pa,pa+100020,-1);
return;
}
inline int par(int x)
{
if(pa[x]==-1)
return x;
return pa[x]=par(pa[x]);
}
inline void uni(int x,int y)
{
x=par(x);
y=par(y);
if(x==y)
return;
pa[x]=y;
return;
}
}uf;
struct seg
{
int mx[800020];
bool mg[800020];
seg(){}
inline void init()
{
fill(mx,mx+800020,-1);
fill(mg,mg+800020,0);
return;
}
inline void prop(int n)
{
if(mg[n])
{
mg[n*2]=mg[n*2+1]=1;
if(mx[n*2]!=-1&&mx[n*2+1]!=-1)
uf.uni(mx[n*2],mx[n*2+1]);
}
mg[n]=0;
return;
}
inline void set(int n,int s,int e,int x,int p)
{
if(s==e)
{
mx[n]=p;
return;
}
prop(n);
int m=(s+e)/2;
if(x>m)
set(n*2+1,m+1,e,x,p);
else
set(n*2,s,m,x,p);
mx[n]=max(mx[n*2],mx[n*2+1]);
return;
}
inline void mrg(int n,int s,int e,int S,int E,int p)
{
if(s>E||S>e||mx[n]==-1)
return;
if(S<=s&&e<=E)
{
uf.uni(mx[n],p);
mg[n]=1;
return;
}
int m=(s+e)/2;
mrg(n*2,s,m,S,E,p);
mrg(n*2+1,m+1,e,S,E,p);
return;
}
}st;
struct fen
{
int t[200020];
fen(){}
inline void init()
{
fill(t,t+200020,0);
return;
}
inline void fi(int x,int p)
{
for(x++;x<200020;x+=x&-x)
t[x]+=p;
return;
}
inline int fs(int x)
{
int s=0;
for(x++;x>0;x=x&(x-1))
s+=t[x];
return s;
}
}ft;
vector<int>vx,vy;
inline ll cpm(const vector<pair<pi,pi> >&v)
{
int vxs=(int)vx.size();
vector<vector<pi> >in(vxs),out(vxs);
vector<vector<pair<pi,int> > >mrg(vxs);
ll s=0;
for(int i=0;i<(int)v.size();i++)
{
auto&t=v[i];
if(t.fi.fi==t.se.fi)
mrg[t.fi.fi].eb(pi(t.fi.se,t.se.se),i);
else
{
in[t.fi.fi].eb(t.fi.se,i);
out[t.se.fi].eb(t.fi.se,i);
}
}
int m=(int)vy.size();
uf.init();
st.init();
ft.init();
for(int i=0;i<(int)vx.size();i++)
{
for(auto&t:in[i])
st.set(1,0,m-1,t.fi,t.se),ft.fi(t.fi,1);
for(auto&t:mrg[i])
st.mrg(1,0,m-1,t.fi.fi,t.fi.se,t.se),s+=ft.fs(t.fi.se)-ft.fs(t.fi.fi-1);
for(auto&t:out[i])
st.set(1,0,m-1,t.fi,-1),ft.fi(t.fi,-1);
}
int cc=0;
for(int i=0;i<(int)v.size();i++)
if(uf.pa[i]==-1)
cc++;
return s+cc;
}
inline int sz(const vector<pair<pi,pi> >&v){return(int)v.size();}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int h,w,n;
cin>>w>>h>>n;
vx.eb(0),vx.eb(w);
vy.eb(0),vy.eb(h);
vector<pair<pi,pi> >edge;
edge.eb(pi(0,0),pi(w,0));
edge.eb(pi(0,0),pi(0,h));
edge.eb(pi(w,0),pi(w,h));
edge.eb(pi(0,h),pi(w,h));
for(int i=0;i<n;i++)
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
edge.eb(pi(x1,y1),pi(x2,y2));
vx.eb(x1),vx.eb(x2);
vy.eb(y1),vy.eb(y2);
}
sort(all(vx)),vx.erase(unique(all(vx)),vx.end());
sort(all(vy)),vy.erase(unique(all(vy)),vy.end());
for(auto&t:edge)
{
t.fi.fi=lower_bound(all(vx),t.fi.fi)-vx.begin();
t.fi.se=lower_bound(all(vy),t.fi.se)-vy.begin();
t.se.fi=lower_bound(all(vx),t.se.fi)-vx.begin();
t.se.se=lower_bound(all(vy),t.se.se)-vy.begin();
}
cout<<cpm(edge)-sz(edge)<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5496 KB |
Output is correct |
2 |
Correct |
8 ms |
5496 KB |
Output is correct |
3 |
Correct |
9 ms |
5368 KB |
Output is correct |
4 |
Correct |
8 ms |
5368 KB |
Output is correct |
5 |
Correct |
8 ms |
5368 KB |
Output is correct |
6 |
Correct |
8 ms |
5368 KB |
Output is correct |
7 |
Correct |
9 ms |
5496 KB |
Output is correct |
8 |
Correct |
10 ms |
5624 KB |
Output is correct |
9 |
Correct |
10 ms |
5496 KB |
Output is correct |
10 |
Correct |
11 ms |
5624 KB |
Output is correct |
11 |
Correct |
10 ms |
5496 KB |
Output is correct |
12 |
Correct |
9 ms |
5496 KB |
Output is correct |
13 |
Correct |
10 ms |
5496 KB |
Output is correct |
14 |
Correct |
10 ms |
5496 KB |
Output is correct |
15 |
Correct |
9 ms |
5500 KB |
Output is correct |
16 |
Correct |
8 ms |
5368 KB |
Output is correct |
17 |
Correct |
8 ms |
5496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5496 KB |
Output is correct |
2 |
Correct |
8 ms |
5496 KB |
Output is correct |
3 |
Correct |
9 ms |
5368 KB |
Output is correct |
4 |
Correct |
8 ms |
5368 KB |
Output is correct |
5 |
Correct |
8 ms |
5368 KB |
Output is correct |
6 |
Correct |
8 ms |
5368 KB |
Output is correct |
7 |
Correct |
9 ms |
5496 KB |
Output is correct |
8 |
Correct |
10 ms |
5624 KB |
Output is correct |
9 |
Correct |
10 ms |
5496 KB |
Output is correct |
10 |
Correct |
11 ms |
5624 KB |
Output is correct |
11 |
Correct |
10 ms |
5496 KB |
Output is correct |
12 |
Correct |
9 ms |
5496 KB |
Output is correct |
13 |
Correct |
10 ms |
5496 KB |
Output is correct |
14 |
Correct |
10 ms |
5496 KB |
Output is correct |
15 |
Correct |
9 ms |
5500 KB |
Output is correct |
16 |
Correct |
8 ms |
5368 KB |
Output is correct |
17 |
Correct |
8 ms |
5496 KB |
Output is correct |
18 |
Correct |
8 ms |
5368 KB |
Output is correct |
19 |
Correct |
8 ms |
5496 KB |
Output is correct |
20 |
Correct |
8 ms |
5368 KB |
Output is correct |
21 |
Correct |
12 ms |
5624 KB |
Output is correct |
22 |
Correct |
10 ms |
5624 KB |
Output is correct |
23 |
Correct |
10 ms |
5624 KB |
Output is correct |
24 |
Correct |
10 ms |
5624 KB |
Output is correct |
25 |
Correct |
10 ms |
5624 KB |
Output is correct |
26 |
Correct |
10 ms |
5624 KB |
Output is correct |
27 |
Correct |
11 ms |
5624 KB |
Output is correct |
28 |
Correct |
10 ms |
5624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
5496 KB |
Output is correct |
2 |
Correct |
9 ms |
5496 KB |
Output is correct |
3 |
Correct |
11 ms |
5496 KB |
Output is correct |
4 |
Correct |
10 ms |
5624 KB |
Output is correct |
5 |
Correct |
29 ms |
7672 KB |
Output is correct |
6 |
Correct |
126 ms |
15216 KB |
Output is correct |
7 |
Correct |
276 ms |
24392 KB |
Output is correct |
8 |
Correct |
270 ms |
24296 KB |
Output is correct |
9 |
Correct |
257 ms |
24540 KB |
Output is correct |
10 |
Correct |
247 ms |
24480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
5496 KB |
Output is correct |
2 |
Correct |
10 ms |
5624 KB |
Output is correct |
3 |
Correct |
31 ms |
7672 KB |
Output is correct |
4 |
Correct |
8 ms |
5368 KB |
Output is correct |
5 |
Correct |
10 ms |
5624 KB |
Output is correct |
6 |
Correct |
354 ms |
24476 KB |
Output is correct |
7 |
Correct |
21 ms |
6776 KB |
Output is correct |
8 |
Correct |
152 ms |
14952 KB |
Output is correct |
9 |
Correct |
176 ms |
15692 KB |
Output is correct |
10 |
Correct |
168 ms |
15464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
5496 KB |
Output is correct |
2 |
Correct |
8 ms |
5496 KB |
Output is correct |
3 |
Correct |
9 ms |
5368 KB |
Output is correct |
4 |
Correct |
8 ms |
5368 KB |
Output is correct |
5 |
Correct |
8 ms |
5368 KB |
Output is correct |
6 |
Correct |
8 ms |
5368 KB |
Output is correct |
7 |
Correct |
9 ms |
5496 KB |
Output is correct |
8 |
Correct |
10 ms |
5624 KB |
Output is correct |
9 |
Correct |
10 ms |
5496 KB |
Output is correct |
10 |
Correct |
11 ms |
5624 KB |
Output is correct |
11 |
Correct |
10 ms |
5496 KB |
Output is correct |
12 |
Correct |
9 ms |
5496 KB |
Output is correct |
13 |
Correct |
10 ms |
5496 KB |
Output is correct |
14 |
Correct |
10 ms |
5496 KB |
Output is correct |
15 |
Correct |
9 ms |
5500 KB |
Output is correct |
16 |
Correct |
8 ms |
5368 KB |
Output is correct |
17 |
Correct |
8 ms |
5496 KB |
Output is correct |
18 |
Correct |
8 ms |
5368 KB |
Output is correct |
19 |
Correct |
8 ms |
5496 KB |
Output is correct |
20 |
Correct |
8 ms |
5368 KB |
Output is correct |
21 |
Correct |
12 ms |
5624 KB |
Output is correct |
22 |
Correct |
10 ms |
5624 KB |
Output is correct |
23 |
Correct |
10 ms |
5624 KB |
Output is correct |
24 |
Correct |
10 ms |
5624 KB |
Output is correct |
25 |
Correct |
10 ms |
5624 KB |
Output is correct |
26 |
Correct |
10 ms |
5624 KB |
Output is correct |
27 |
Correct |
11 ms |
5624 KB |
Output is correct |
28 |
Correct |
10 ms |
5624 KB |
Output is correct |
29 |
Correct |
9 ms |
5496 KB |
Output is correct |
30 |
Correct |
9 ms |
5496 KB |
Output is correct |
31 |
Correct |
11 ms |
5496 KB |
Output is correct |
32 |
Correct |
10 ms |
5624 KB |
Output is correct |
33 |
Correct |
29 ms |
7672 KB |
Output is correct |
34 |
Correct |
126 ms |
15216 KB |
Output is correct |
35 |
Correct |
276 ms |
24392 KB |
Output is correct |
36 |
Correct |
270 ms |
24296 KB |
Output is correct |
37 |
Correct |
257 ms |
24540 KB |
Output is correct |
38 |
Correct |
247 ms |
24480 KB |
Output is correct |
39 |
Correct |
9 ms |
5496 KB |
Output is correct |
40 |
Correct |
10 ms |
5624 KB |
Output is correct |
41 |
Correct |
31 ms |
7672 KB |
Output is correct |
42 |
Correct |
8 ms |
5368 KB |
Output is correct |
43 |
Correct |
10 ms |
5624 KB |
Output is correct |
44 |
Correct |
354 ms |
24476 KB |
Output is correct |
45 |
Correct |
21 ms |
6776 KB |
Output is correct |
46 |
Correct |
152 ms |
14952 KB |
Output is correct |
47 |
Correct |
176 ms |
15692 KB |
Output is correct |
48 |
Correct |
168 ms |
15464 KB |
Output is correct |
49 |
Correct |
10 ms |
5496 KB |
Output is correct |
50 |
Correct |
10 ms |
5624 KB |
Output is correct |
51 |
Correct |
10 ms |
5496 KB |
Output is correct |
52 |
Correct |
161 ms |
15472 KB |
Output is correct |
53 |
Correct |
122 ms |
15340 KB |
Output is correct |
54 |
Correct |
158 ms |
15468 KB |
Output is correct |
55 |
Correct |
345 ms |
24428 KB |
Output is correct |
56 |
Correct |
272 ms |
24556 KB |
Output is correct |
57 |
Correct |
350 ms |
24552 KB |
Output is correct |
58 |
Correct |
347 ms |
24576 KB |
Output is correct |
59 |
Correct |
165 ms |
15336 KB |
Output is correct |
60 |
Correct |
176 ms |
15592 KB |
Output is correct |
61 |
Correct |
178 ms |
15336 KB |
Output is correct |
62 |
Correct |
186 ms |
15592 KB |
Output is correct |
63 |
Correct |
338 ms |
24424 KB |
Output is correct |
64 |
Correct |
255 ms |
24424 KB |
Output is correct |
65 |
Correct |
362 ms |
24552 KB |
Output is correct |
66 |
Correct |
344 ms |
24512 KB |
Output is correct |
67 |
Correct |
315 ms |
24532 KB |
Output is correct |
68 |
Correct |
313 ms |
24552 KB |
Output is correct |
69 |
Correct |
309 ms |
24552 KB |
Output is correct |
70 |
Correct |
313 ms |
24552 KB |
Output is correct |
71 |
Correct |
183 ms |
19436 KB |
Output is correct |
72 |
Correct |
215 ms |
11752 KB |
Output is correct |