Submission #660624

#TimeUsernameProblemLanguageResultExecution timeMemory
660624Dec0DeddDominance (CEOI08_dominance)C++14
65 / 100
13 ms468 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<ll, ll> #define ll long long #define pp pair<pair<int, pii>, bool> const int N = 1e5+1; const ll INF = 1e17; ll sm[N]; struct Ev { ll x, lf, rf; bool add; }; vector<Ev> v; bool cmp(Ev a, Ev b) { if (a.x == b.x) return a.add < b.add; return a.x < b.x; } ll calc(int x1, int y1, int x2, int y2) { if ((x2-x1)*(y2-y1)%2 == 0) return (x2-x1)*(y2-y1)/2; return (x2-x1)*(y2-y1)/2+(((x1^y1)&1) == 0); } int main() { int n, h, w; cin>>h>>w>>n; vector<ll> ys; for (int i=1; i<=n; ++i) { char c; cin>>c; ll x, y, r, xp, yp; cin>>x>>y>>r; xp=x-y, yp=x+y; bool b; if (c == 'W') b=true; else b=false; v.push_back(Ev{xp-r, yp-r, yp+r, b}); v.push_back(Ev{xp+r+1, yp-r, yp+r, !b}); ys.push_back(yp-r), ys.push_back(yp+r); ys.push_back(yp-r+1), ys.push_back(yp+r+1); } sort(ys.begin(), ys.end()); ys.erase(unique(ys.begin(), ys.end()), ys.end()); sort(v.begin(), v.end(), cmp); pii ans={0, 0}; ll lst=0; for (auto u : v) { for (int j=1; j<(int)ys.size(); ++j) { if (sm[j] > 0) ans.first+=calc(lst, ys[j-1], u.x, ys[j]); else if (sm[j] < 0) ans.second+=calc(lst, ys[j-1], u.x, ys[j]); } int lb=upper_bound(ys.begin(), ys.end(), u.lf)-ys.begin(); int ub=upper_bound(ys.begin(), ys.end(), u.rf)-ys.begin(), k; if (u.add) k=1; else k=-1; for (int j=lb; j<=ub; ++j) sm[j]+=k; lst=u.x; } cout<<ans.first<<" "<<ans.second<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...