답안 #660626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660626 2022-11-22T17:14:30 Z Dec0Dedd Dominance (CEOI08_dominance) C++14
100 / 100
14 ms 496 KB
#include <bits/stdc++.h>

using namespace std;

#define pii pair<ll, ll>
#define ll long long

const int N = 1e5+1;

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(ll x1, ll y1, ll x2, ll 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";
} 
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 9 ms 440 KB Output is correct
5 Correct 13 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 Correct 6 ms 340 KB Output is correct
9 Correct 10 ms 468 KB Output is correct
10 Correct 13 ms 488 KB Output is correct
11 Correct 14 ms 468 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 14 ms 496 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 14 ms 472 KB Output is correct
16 Correct 8 ms 460 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 320 KB Output is correct
20 Correct 2 ms 340 KB Output is correct