Submission #755022

# Submission time Handle Problem Language Result Execution time Memory
755022 2023-06-09T10:06:11 Z bgnbvnbv Dominance (CEOI08_dominance) C++14
100 / 100
82 ms 1148 KB
#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

dominance.cpp: In function 'void solve()':
dominance.cpp:77:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |     for(int i=1;i<vecc.size();i++)
      |                 ~^~~~~~~~~~~~
dominance.cpp:89:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for(int i=1;i<vecr.size();i++)
      |                 ~^~~~~~~~~~~~
dominance.cpp:103:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |         for(int j=0;j<cordr.size();j++)
      |                     ~^~~~~~~~~~~~~
dominance.cpp:114:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |         for(int j=0;j<cordc.size();j++)
      |                     ~^~~~~~~~~~~~~
dominance.cpp:133:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |     for(int i=0;i<cordr.size();i++)
      |                 ~^~~~~~~~~~~~~
dominance.cpp:146:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  146 |         for(int j=1;j<cordc.size();j++)
      |                     ~^~~~~~~~~~~~~
dominance.cpp:150:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  150 |         for(int j=0;j<cordc.size();j++)
      |                     ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 2 ms 944 KB Output is correct
3 Correct 5 ms 980 KB Output is correct
4 Correct 46 ms 1128 KB Output is correct
5 Correct 55 ms 1148 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 29 ms 980 KB Output is correct
9 Correct 61 ms 1104 KB Output is correct
10 Correct 70 ms 1136 KB Output is correct
11 Correct 82 ms 1120 KB Output is correct
12 Correct 1 ms 852 KB Output is correct
13 Correct 72 ms 1136 KB Output is correct
14 Correct 1 ms 852 KB Output is correct
15 Correct 46 ms 1100 KB Output is correct
16 Correct 11 ms 1100 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 6 ms 980 KB Output is correct
19 Correct 2 ms 980 KB Output is correct
20 Correct 7 ms 996 KB Output is correct