#include <iostream>
#include <set>
using namespace std;
typedef long long ll;
struct node{
set <int> s;
};
int a, b, n, di;
node t[2][(1 << 18) + 5];
ll res;
const ll inf = (ll) 1e18;
void update(int root, int l, int r, int s, int e, int val){
if(l > r || l > e || r < s)
return;
if(l >= s && r <= e){
t[di][root].s.insert(val);
return;
}
int mid = (l + r) / 2;
update(root * 2, l, mid, s, e, val);
update(root * 2 + 1, mid + 1, r, s, e, val);
}
void query(int root, int l, int r, int idx, int val, bool type){
if(l > r || l > idx || r < idx)
return;
if(type){
set <int>::iterator it = t[di][root].s.upper_bound(val);
if(!t[di][root].s.empty() && it != t[di][root].s.end()){
res = min(res, (ll)*it);
}
}
else{
set <int>::iterator it = t[di][root].s.upper_bound(val);
if(!t[di][root].s.empty() && it != t[di][root].s.begin()){
res = max(res, (ll)*(--it));
}
}
if(l == r)
return;
int mid = (l + r) / 2;
if(idx <= mid){
query(root * 2, l, mid, idx, val, type);
return;
}
query(root * 2 + 1, mid + 1, r, idx, val, type);
}
int kolko(int l, int r, int x, int y, bool type){
if(type){
res = inf;
}
else{
res = 0;
}
query(1, l, r, x, y, type);
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> a >> b;
update(1, 1, a, 1, a, 0);
update(1, 1, a, 1, a, b);
di = 1;
update(1, 1, b, 1, b, 0);
update(1, 1, b, 1, b, a);
//cout << 1 << endl;
cin >> n;
for(int i = 0 ; i < n ; ++i){
int x, y, type;
cin >> x >> y >> type;
if(type == 1){
di = 1;
int l = kolko(1, b, y, x, 0);
int r = kolko(1, b, y, x, 1);
di = 0;
int dolje = kolko(1, a, x, y, 0);
int gore = kolko(1, a, x, y, 1);
ll p1 = (ll)(gore - y) * (ll)(r - l);
ll p2 = (ll)(y - dolje) * (ll)(r - l);
if(p1 > p2){
swap(p1, p2);
}
cout << p1 << ' ' << p2 << endl;
update(1, 1, a, l, r, y);
}
else{
di = 0;
int dolje = kolko(1, a, x, y, 0);
int gore = kolko(1, a, x, y, 1);
di = 1;
int l = kolko(1, b, y, x, 0);
int r = kolko(1, b, y, x, 1);
ll p1 = (ll)(r - x) * (ll)(gore - dolje);
ll p2 = (ll)(x - l) * (ll)(gore - dolje);
if(p1 > p2){
swap(p1, p2);
}
cout << p1 << ' ' << p2 << endl;
update(1, 1, b, dolje, gore, x);
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
25088 KB |
Output is correct |
2 |
Correct |
22 ms |
25088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
25464 KB |
Output is correct |
2 |
Correct |
29 ms |
25856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
225 ms |
30472 KB |
Output is correct |
2 |
Correct |
214 ms |
30328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
227 ms |
30696 KB |
Output is correct |
2 |
Correct |
248 ms |
31096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
30584 KB |
Output is correct |
2 |
Correct |
276 ms |
32052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
467 ms |
39332 KB |
Output is correct |
2 |
Correct |
484 ms |
53836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1233 ms |
54300 KB |
Output is correct |
2 |
Correct |
531 ms |
58488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1043 ms |
53552 KB |
Output is correct |
2 |
Correct |
463 ms |
63740 KB |
Output is correct |
3 |
Correct |
291 ms |
32504 KB |
Output is correct |
4 |
Correct |
607 ms |
60924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1206 ms |
54564 KB |
Output is correct |
2 |
Correct |
511 ms |
67360 KB |
Output is correct |
3 |
Correct |
301 ms |
32908 KB |
Output is correct |
4 |
Correct |
583 ms |
63264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1074 ms |
54704 KB |
Output is correct |
2 |
Correct |
423 ms |
57592 KB |
Output is correct |
3 |
Correct |
301 ms |
32800 KB |
Output is correct |
4 |
Correct |
622 ms |
65584 KB |
Output is correct |