Submission #644020

#TimeUsernameProblemLanguageResultExecution timeMemory
644020Do_you_copyDominance (CEOI08_dominance)C++17
100 / 100
13 ms572 KiB
//////////////////////////// // 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 (stderr)

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 timeMemoryGrader output
Fetching results...