#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
const int inf = 1e16;
const ll mod2 = 1e9+9999;
const int mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
if(x+y>=mod2) x-=mod2;
if(x+y<0)x+=mod2;
return x+y;
}
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
ll a;
int b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,lim,w ;
int kk;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
// modwwe
phongbeo();
// checktime
}
ib dsu[200018];
vector<int> v;
vector<ib> ask[200018];
vector<ic> query[200018];
vector<ib>v2;
id a[200018];
int pos[200018];
void reset()
{
for(int i=1; i<=n; i++)
dsu[i]= {1,i};
}
int get(int x)
{
if(x==dsu[x].b) return x;
return dsu[x].b=get(dsu[x].b);
}
void noi(int x,int y)
{
x=get(x);
y=get(y);
if(x==y)
{
mx++;
return;
}
if(dsu[x].a<dsu[y].a) swap(x,y);
dsu[x].a+=dsu[y].a;
dsu[y].b=x;
}
void build(int x,int y,int c,int b)
{
k++;
v.pb(x),v.pb(y),v.pb(c),v.pb(b);
a[k]= {x,y,c,b};
}
bool cmp(ib a,ib b)
{
return a.a<b.a;
}
int t[810018],ch[810018];
void ff(int x)
{
for(int i=x*2; i<=x*2+1; i++)
{
if(ch[i]==0 )continue;
if(t[i]!=0) noi(t[i],t[x]);
t[i]=get(t[x]);
}
t[x]=0;
}
void upd(int node,int l,int r,int l1,int k)
{
if(k<0)ch[node]--;
else ch[node]+=1;
if(l==r)
{
if(k<0&&t[node]!=0)noi(-k,t[node]);
t[node]=0;
return;
}
int mid=l+r>>1;
if(t[node]!=0)ff(node);
if(l1<=mid) upd(node<<1,l,mid,l1,k);
else upd(node<<1|1,mid+1,r,l1,k);
}
void upd2(int node,int l,int r,int l1,int r1,int k)
{
if(l>r1||r<l1||ch[node]==0) return;
if(l>=l1&&r<=r1)
{
if(t[node]!=0) noi(t[node],k);
t[node]=get(k);
s4+=ch[node];
return;
}
if(t[node]!=0) ff(node);
int mid=l+r>>1;
upd2(node<<1,l,mid,l1,r1,k);
upd2(node<<1|1,mid+1,r,l1,r1,k);
}
void phongbeo()
{
cin>>n>>m>>k;
for(int i=1; i<=k; i++)
cin>>a[i].a>>a[i].b>>a[i].c>>a[i].d,
v.pb(a[i].a),v.pb(a[i].c);
build(0,0,0,m);
build(0,0,n,0);
build(n,0,n,m);
build(0,m,n,m);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
for(int i=1; i<=k; i++)
{
a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1;
a[i].c=lower_bound(v.begin(),v.end(),a[i].c)-v.begin()+1;
if(a[i].a==a[i].c)
query[a[i].a].pb({a[i].b,a[i].d,i});
else
{
ask[a[i].a].pb({i,1}),
ask[a[i].c].pb({i,-1});
}
}
int all=v.size();
vector<int>().swap(v);
for(int i=1; i<=k; i++)
if(a[i].b==a[i].d)
{
v.pb(a[i].b);
v2.pb({a[i].b,i});
}
sort(v.begin(),v.end());
sort(v2.begin(),v2.end(),cmp);
for(int i=0; i<v2.size(); i++)
pos[v2[i].b]=i+1;
n=k;
reset();
s4=0;
for(int i=1; i<=all; i++)
{
for(auto x:ask[i])
{
if(x.b==-1) continue;
upd(1,1,n,pos[x.a],x.a*x.b);
}
for(auto x:query[i])
{
int low=lower_bound(v.begin(),v.end(),x.a)-v.begin()+1;
int high=upper_bound(v.begin(),v.end(),x.b)-v.begin();
upd2(1,1,n,low,high,x.c);
}
for(auto x:ask[i])
{
if(x.b==1) continue;
upd(1,1,n,pos[x.a],x.a*x.b);
}
}
for(int i=1; i<=n; i++)
if(dsu[i].b==i)
s4=s4-dsu[i].a+1;
cout<<s4;
}
Compilation message (stderr)
2014_ho_t5.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
58 | main()
| ^~~~
2014_ho_t5.cpp: In function 'int main()':
2014_ho_t5.cpp:12:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
2014_ho_t5.cpp:62:9: note: in expansion of macro 'fin'
62 | fin(task);
| ^~~
2014_ho_t5.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define fou(x) freopen(x".out","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
2014_ho_t5.cpp:63:9: note: in expansion of macro 'fou'
63 | fou(task);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |