Submission #854780

#TimeUsernameProblemLanguageResultExecution timeMemory
854780TadijaSebezDominance (CEOI08_dominance)C++17
100 / 100
30 ms736 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long const ll lim=2e9; const int N=3050; int x[N],y[N],r[N]; char col[N]; ll Get(ll L,ll R,ll diff){ if(abs(L)%2!=diff%2)L++; if(abs(R)%2!=diff%2)R--; if(L>R)return 0; return (R-L+2)/2; } void Split(vector<array<ll,3>>& all,ll val){ vector<array<ll,3>> ans; for(auto x:all){ if(x[0]<=val && x[1]>=val){ if(x[0]<val){ ans.pb({x[0],val-1,x[2]}); ans.pb({val,x[1],x[2]}); }else{ ans.pb(x); } }else{ ans.pb(x); } } all=ans; } int main(){ int n; scanf("%*i %*i %i",&n); vector<pair<int,int>> evs; for(int i=1;i<=n;i++){ scanf("\n%c %i %i %i",&col[i],&x[i],&y[i],&r[i]); evs.pb({x[i]+y[i]-r[i],-i}); evs.pb({x[i]+y[i]+r[i]+1,i}); } sort(evs.begin(),evs.end()); vector<array<ll,3>> all; all.pb({-lim,lim,0}); ll last=2; ll W=0,B=0; for(auto ev:evs){ int i=abs(ev.second); ll diff=ev.first-last; ll even=(diff+1)/2; ll odd=diff/2; for(auto x:all){ ll add=even*Get(x[0],x[1],last)+odd*Get(x[0],x[1],last+1); if(x[2]!=0){ //printf("add:%lld e:%lld o:%lld [%lld %lld]\n",add,Get(x[0],x[1],last),Get(x[0],x[1],last+1),x[0],x[1]); } if(x[2]>0)W+=add; else if(x[2]<0)B+=add; } //printf("i:%i W:%lld B:%lld diff:%lld even:%lld odd:%lld\n",i,W,B,diff,even,odd); ll add=col[i]=='W'?1:-1; if(ev.second>0){ add=-add; } ll L=x[i]-y[i]-r[i]; ll R=x[i]-y[i]+r[i]; Split(all,L); Split(all,R+1); for(auto &x:all){ if(x[0]>=L && x[1]<=R){ x[2]+=add; } } last=ev.first; } printf("%lld %lld\n",W,B); return 0; }

Compilation message (stderr)

dominance.cpp: In function 'int main()':
dominance.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  scanf("%*i %*i %i",&n);
      |  ~~~~~^~~~~~~~~~~~~~~~~
dominance.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("\n%c %i %i %i",&col[i],&x[i],&y[i],&r[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...