This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define uset unordered_set
#define endl '\n'
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
const int inf = 2e9;
const int N = 1e5 + 15;
int w, h, n, m, k;
set <int> t[2][N << 2];
void multiupdate(int v, int tl, int tr, int l, int r, int val, int isx) {
if(tl > r || tr < l || l > r)
return;
if(tl >= l && tr <= r) {
t[isx][v].insert(val);
return;
}
int mid = tl + tr >> 1;
multiupdate(v << 1, tl, mid, l, r, val, isx);
multiupdate(v << 1 | 1, mid + 1, tr, l, r, val, isx);
}
pii get(int v, int tl, int tr, int pos, int x, int isx) {
pii ans = mp(-inf, inf);
set <int>::iterator it = t[isx][v].upper_bound(x);
if(it != t[isx][v].end())
ans.se = min(ans.se, *it);
if(it != t[isx][v].begin())
ans.f = max(ans.f, *(--it));
if(tl == tr)
return ans;
int mid = tl + tr >> 1;
if(pos <= mid) {
pii s = get(v << 1, tl, mid, pos, x, isx);
return mp(max(s.f, ans.f), min(s.se, ans.se));
}
pii s = get(v << 1 | 1, mid + 1, tr, pos, x, isx);
return mp(max(s.f, ans.f), min(s.se, ans.se));
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> w >> h >> n;
multiupdate(1, 1, h, 1, h, 0, 0);
multiupdate(1, 1, h, 1, h, w, 0);
multiupdate(1, 1, w, 1, w, 0, 1);
multiupdate(1, 1, w, 1, w, h, 1);
for(int i = 1; i <= n; ++i) {
int x, y, d;
cin >> x >> y >> d;
if(d == 1) {
pii x12 = get(1, 1, h, y, x, 0);
pii y12 = get(1, 1, w, x, y, 1);
ll area1 = (ll)abs(y - y12.f) * abs(x12.f - x12.se);
ll area2 = (ll)abs(y - y12.se) * abs(x12.f - x12.se);
if(area2 < area1)
swap(area2, area1);
cout << area1 << ' ' << area2 << endl;
multiupdate(1, 1, w, x12.f, x12.se, y, 1);
}
else {
pii x12 = get(1, 1, h, y, x, 0);
pii y12 = get(1, 1, w, x, y, 1);
ll area1 = (ll)abs(y12.se - y12.f) * abs(x - x12.se);
ll area2 = (ll)abs(y12.se - y12.f) * abs(x12.f - x);
if(area2 < area1)
swap(area2, area1);
cout << area1 << ' ' << area2 << endl;
multiupdate(1, 1, h, y12.f, y12.se, x, 0);
}
}
return 0;
}
Compilation message (stderr)
krave.cpp: In function 'void multiupdate(int, int, int, int, int, int, int)':
krave.cpp:34:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
krave.cpp: In function 'std::pair<int, int> get(int, int, int, int, int, int)':
krave.cpp:53:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |