#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
struct obdl { int r1, c1, r2, c2; };
const ll inf = 1e10;
ll count(ll r1, ll c1, ll r2, ll c2) // spocita pocet platnych bodov, vratane
{
r1 += inf, c1 += inf, r2 += inf, c2 += inf;
ll even_rows = r2/2 - (r1-1)/2, odd_rows = r2 - r1 + 1 - even_rows;
ll even_columns = c2/2 - (c1-1)/2, odd_columns = c2 - c1 + 1 - even_columns;
return even_rows * even_columns + odd_rows * odd_columns;
}
struct udalost { ll x, y1, y2; int d; };
bool cmp(const udalost &a, const udalost &b) { return a.x < b.x; }
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int w, h, n;
cin >> w >> h >> n;
vector<udalost> e;
set<int> sy;
for (int i = 0, x, y, d; i < n; i++)
{
char c;
cin >> c >> x >> y >> d;
int delta = c == 'W' ? 1 : -1;
e.push_back({x-y-d, x+y-d, x+y+d+1, delta});
e.push_back({x-y+d+1, x+y-d, x+y+d+1, -delta});
}
for (udalost i : e) sy.insert(i.y1), sy.insert(i.y2);
vector<int> vy(sy.begin(), sy.end()), sum(vy.size(), 0);
sort(e.begin(), e.end(), cmp);
ll cntw = 0, cntb = 0;
//for (int j = 0; j < vy.size(); j++) cout << vy[j] << " ";
//cout << endl << "============" << endl;
for (int i = 0; i < e.size()-1; i++)
{
for (int j = 0; j < vy.size(); j++) if (e[i].y1 <= vy[j] && vy[j] < e[i].y2)
sum[j] += e[i].d;
for (int j = 0; j < vy.size() - 1; j++)
{
ll ok = count(e[i].x, vy[j], e[i+1].x-1, vy[j+1]-1);
if (sum[j] > 0) cntw += ok;
if (sum[j] < 0) cntb += ok;
}
//for (int j = 0; j < vy.size(); j++) cout << sum[j] << " ";
//cout << "| " << e[i].x << endl;
}
cout << cntw << " " << cntb << "\n";
return 0;
}
Compilation message
dominance.cpp: In function 'int main()':
dominance.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<udalost>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int i = 0; i < e.size()-1; i++)
| ~~^~~~~~~~~~~~
dominance.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int j = 0; j < vy.size(); j++) if (e[i].y1 <= vy[j] && vy[j] < e[i].y2)
| ~~^~~~~~~~~~~
dominance.cpp:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int j = 0; j < vy.size() - 1; j++)
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
13 ms |
488 KB |
Output is correct |
5 |
Correct |
18 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
8 ms |
448 KB |
Output is correct |
9 |
Correct |
13 ms |
460 KB |
Output is correct |
10 |
Correct |
15 ms |
496 KB |
Output is correct |
11 |
Correct |
17 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
18 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
312 KB |
Output is correct |
15 |
Correct |
15 ms |
460 KB |
Output is correct |
16 |
Correct |
15 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
19 |
Correct |
3 ms |
332 KB |
Output is correct |
20 |
Correct |
2 ms |
332 KB |
Output is correct |