Submission #660624

# Submission time Handle Problem Language Result Execution time Memory
660624 2022-11-22T17:05:15 Z Dec0Dedd Dominance (CEOI08_dominance) C++14
65 / 100
13 ms 468 KB
#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 time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 340 KB Output is correct
5 Correct 7 ms 468 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Incorrect 4 ms 340 KB Output isn't correct
9 Incorrect 8 ms 340 KB Output isn't correct
10 Incorrect 10 ms 456 KB Output isn't correct
11 Incorrect 10 ms 340 KB Output isn't correct
12 Incorrect 0 ms 212 KB Output isn't correct
13 Incorrect 8 ms 468 KB Output isn't correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 13 ms 448 KB Output is correct
16 Correct 6 ms 340 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Incorrect 1 ms 340 KB Output isn't correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct