#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 N = 1e5 + 15;
int w, h, n, m, k;
vector <int> add[2][N << 2];
set <int> t[2][N << 2];
inline void push(int v, int isx) {
while(!add[isx][v].empty()) {
if(v < (N << 1)) {
add[isx][v << 1].pb(add[isx][v].back());
add[isx][v << 1 | 1].pb(add[isx][v].back());
t[isx][v << 1].insert(add[isx][v].back());
t[isx][v << 1 | 1].insert(add[isx][v].back());
}
add[isx][v].ppb();
}
}
void multiupdate(int v, int tl, int tr, int l, int r, int val, int isx) {
if(tl > r || tr < l || l > r)
return;
push(v, isx);
if(tl >= l && tr <= r) {
t[isx][v].insert(val);
add[isx][v].pb(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) {
push(v, isx);
if(tl == tr)
return mp(*(--t[isx][v].upper_bound(x)), *t[isx][v].upper_bound(x));
int mid = tl + tr >> 1;
if(pos <= mid)
return get(v << 1, tl, mid, pos, x, isx);
return get(v << 1 | 1, mid + 1, tr, pos, x, isx);
}
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:48: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:57:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = tl + tr >> 1;
~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
60152 KB |
Output is correct |
2 |
Correct |
61 ms |
58872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
90944 KB |
Output is correct |
2 |
Runtime error |
666 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
739 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
745 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
743 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
809 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
765 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
794 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
755 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
805 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |