Submission #644020

# Submission time Handle Problem Language Result Execution time Memory
644020 2022-09-23T13:06:03 Z Do_you_copy Dominance (CEOI08_dominance) C++17
100 / 100
13 ms 572 KB
////////////////////////////
// Gke vay sao            //
////////////////////////////
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using ull = unsigned ll;
using ld = long double;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

template <class T> inline T min(const T &a, const T &b){
    return (a < b) ? a : b;
}

template <class T> inline T max(const T &a, const T &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000007;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;
int W, H, n;

struct TBug{
    int c, x, y, r;
};
TBug bug[maxN];

struct TSeg{
    int x, y1, y2, t;
};

inline int cal(int x1, int y1, int x2, int y2){
    //calculate the number of "odd sum (x + y)" coordinates
    if ((x2 - x1) * (y2 - y1) % 2 == 0) return (x2 - x1) * (y2 - y1) / 2;
    return (x2 - x1) * (y2 - y1) / 2 + (((x1 ^ y1) & 1) == 0);
}
vector <TSeg> E;
int a[maxN];
void Init(){
    cin >> W >> H >> n;
    ll ans1 = 0, ans2 = 0;
    vector <int> v;
    for (int i = 1; i <= n; ++i){
        char c; cin >> c;
        if (c == 'W') bug[i].c = 1;
        else bug[i].c = -1;
        cin >> bug[i].x >> bug[i].y >> bug[i].r;
        bug[i].x = bug[i].x - bug[i].y;
        bug[i].y = bug[i].x + 2 * bug[i].y;
        //x - y, x + y
        //square:
        //x - r, y - r  || x + r, y - r
        //-----------------------------------------------
        //x - r, y + r  || x + r, y + r
        E.pb({bug[i].x - bug[i].r, bug[i].y - bug[i].r, bug[i].y + bug[i].r, bug[i].c});
        E.pb({bug[i].x + bug[i].r + 1, bug[i].y - bug[i].r, bug[i].y + bug[i].r, -bug[i].c});
        v.pb(bug[i].y - bug[i].r);
        v.pb(bug[i].y + bug[i].r);
        v.pb(bug[i].y - bug[i].r + 1);
        v.pb(bug[i].y + bug[i].r + 1);
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    sort(E.begin(), E.end(),[](const auto &i, const auto &j){
        if (i.x == j.x) return i.t < j.t;
        return i.x < j.x;
    });
    ll last = 0;
    for (auto &i: E){
        for (int j = 1; j < v.size(); ++j){
            if (a[j] > 0){
                ans1 += cal(last, v[j - 1], i.x, v[j]);
            }
            if (a[j] < 0){
                ans2 += cal(last, v[j - 1], i.x, v[j]);
            }
        }
        int k1 = upper_bound(v.begin(), v.end(), i.y1) - v.begin();
        int k2 = upper_bound(v.begin(), v.end(), i.y2) - v.begin();
        //update from k1 to k2
        for (int j = k1; j <= k2; ++j){
            a[j] += i.t;
        }
        last = i.x;
    }
    cout << ans1 << " " << ans2 << "\n";
}

#define debu
#define taskname "test"
signed main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        #ifdef debug
        freopen(taskname".out", "w", stdout);
        #endif
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
    #ifdef debug
        ofstream timeout("timeout.txt");
        timeout << signed(1000 * double(clock()) / CLOCKS_PER_SEC);
        timeout.close();
    #else
        cerr << "\nTime elapsed: " << 1000 * double(clock()) / CLOCKS_PER_SEC << "ms\n";
    #endif
}

Compilation message

dominance.cpp: In function 'void Init()':
dominance.cpp:81:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for (int j = 1; j < v.size(); ++j){
      |                         ~~^~~~~~~~~~
dominance.cpp: In function 'int main()':
dominance.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 9 ms 468 KB Output is correct
5 Correct 5 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 5 ms 468 KB Output is correct
9 Correct 9 ms 544 KB Output is correct
10 Correct 10 ms 468 KB Output is correct
11 Correct 12 ms 572 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 10 ms 572 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 13 ms 468 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct