#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
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;
~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
38008 KB |
Output is correct |
2 |
Correct |
37 ms |
38008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
38392 KB |
Output is correct |
2 |
Correct |
42 ms |
38756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
155 ms |
43416 KB |
Output is correct |
2 |
Correct |
134 ms |
43256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
43512 KB |
Output is correct |
2 |
Correct |
153 ms |
44280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
43664 KB |
Output is correct |
2 |
Correct |
166 ms |
44884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
336 ms |
52368 KB |
Output is correct |
2 |
Correct |
345 ms |
66808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
816 ms |
67356 KB |
Output is correct |
2 |
Correct |
394 ms |
71544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
750 ms |
66320 KB |
Output is correct |
2 |
Correct |
414 ms |
76540 KB |
Output is correct |
3 |
Correct |
167 ms |
45432 KB |
Output is correct |
4 |
Correct |
424 ms |
73820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
854 ms |
67528 KB |
Output is correct |
2 |
Correct |
489 ms |
80464 KB |
Output is correct |
3 |
Correct |
173 ms |
45944 KB |
Output is correct |
4 |
Correct |
444 ms |
76152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
782 ms |
67696 KB |
Output is correct |
2 |
Correct |
351 ms |
70776 KB |
Output is correct |
3 |
Correct |
173 ms |
45688 KB |
Output is correct |
4 |
Correct |
514 ms |
78428 KB |
Output is correct |