# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
755022 | bgnbvnbv | Dominance (CEOI08_dominance) | C++14 | 82 ms | 1148 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=3006;
const ll inf=1e18;
const ll mod=1e9+7;
int f[3005*4],g[3005*4],L[maxN],R[maxN];
vector<ll>in[3005*4],out[3005*4];
ll w,h;
ll n,x[maxN],y[maxN],r[maxN];
char c[maxN];
ll val[maxN];
vector<ll>vecc,vecr;
ll get(ll r1,ll l1,ll r2,ll l2)
{
ll le,chan,le1,chan1;
if((r2-l2+1)%2==0)
{
le=(r2-l2+1)/2;
chan=(r2-l2+1)/2;
}
else
{
le=(r2-l2+1)/2;
chan=(r2-l2+1)/2;
if(r2%2==0)
{
chan++;
//le--;
}
else le++;
}
swap(le,le1);
swap(chan,chan1);
swap(r1,r2);
swap(l1,l2);
if((r2-l2+1)%2==0)
{
le=(r2-l2+1)/2;
chan=(r2-l2+1)/2;
}
else
{
le=(r2-l2+1)/2;
chan=(r2-l2+1)/2;
if(r2%2==0)
{
chan++;
//le--;
}
else le++;
}
return (le*le1)+(chan*chan1);
}
void solve()
{
cin >> w >> h;
cin >> n;
for(int i=1;i<=n;i++)
{
cin >> c[i] >> x[i] >> y[i] >> r[i];
vecc.pb({x[i]-y[i]+r[i]});
vecc.pb({x[i]-y[i]-r[i]});
vecr.pb({x[i]+y[i]-r[i]});
vecr.pb({x[i]+y[i]+r[i]});
}
sort(vecc.begin(),vecc.end());
sort(vecr.begin(),vecr.end());
vector<pli> cordr,cordc;
cordc.pb({vecc[0],vecc[0]});
for(int i=1;i<vecc.size();i++)
{
if(vecc[i]!=vecc[i-1])
{
if(vecc[i]-vecc[i-1]>=2)
{
cordc.pb({vecc[i-1]+1,vecc[i]-1});
}
cordc.pb({vecc[i],vecc[i]});
}
}
cordr.pb({vecr[0],vecr[0]});
for(int i=1;i<vecr.size();i++)
{
if(vecr[i]!=vecr[i-1])
{
if(vecr[i]-vecr[i-1]>=2)
{
cordr.pb({vecr[i-1]+1,vecr[i]-1});
}
cordr.pb({vecr[i],vecr[i]});
}
}
for(int i=1;i<=n;i++)
{
ll l1=inf,r1=inf,l2=inf,r2=inf;
for(int j=0;j<cordr.size();j++)
{
if(cordr[j].se>=x[i]+y[i]-r[i])
{
l1=min(l1,1ll*j);
}
if(cordr[j].se>=x[i]+y[i]+r[i])
{
r1=min(r1,1ll*j);
}
}
for(int j=0;j<cordc.size();j++)
{
if(cordc[j].se>=x[i]-y[i]-r[i])
{
l2=min(l2,1ll*j);
}
if(cordc[j].se>=x[i]-y[i]+r[i])
{
r2=min(r2,1ll*j);
}
}
L[i]=l2;
R[i]=r2;
in[l1].pb(i);
out[r1+1].pb(i);
if(c[i]=='W') val[i]=1;
else val[i]=-1;
}
ll ans1=0,ans2=0;
for(int i=0;i<cordr.size();i++)
{
for(auto id:in[i])
{
f[L[id]]+=val[id];
f[R[id]+1]-=val[id];
}
for(auto id:out[i])
{
f[L[id]]-=val[id];
f[R[id]+1]+=val[id];
}
g[0]=f[0];
for(int j=1;j<cordc.size();j++)
{
g[j]=g[j-1]+f[j];
}
for(int j=0;j<cordc.size();j++)
{
if(g[j]<0)
{
ans1+=get(cordr[i].se,cordr[i].fi,cordc[j].se,cordc[j].fi);
}
else if(g[j]>0) ans2+=get(cordr[i].se,cordr[i].fi,cordc[j].se,cordc[j].fi);
}
}
cout << ans2<<' '<<ans1;
// x=x+y
// y=x-y
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |