#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
void io() {
#ifdef LOCAL_PROJECT
freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else
/* online submission */
#endif
ios_base::sync_with_stdio(false); cin.tie(NULL);
}
const ll MOD = 1000000007LL;
const ll PRIME = 105943LL;
const int INF = 1e8;
/****************************************************************/
template <int K> struct SegmentTree {
static const int SZ = 1 << K;
set<int> data[SZ << 1];
void init(int lb, int ub) {
FOR(i, 1, 2 * SZ)
data[i].insert(lb), data[i].insert(ub);
}
pii query(int pos, int x) { // query in pos bounds for x
pos += SZ;
int lo = -INF, hi = INF;
while (pos) {
auto it = data[pos].upper_bound(x);
minn(hi, *it);
it--;
maxx(lo, *it);
pos /= 2;
}
return{ lo, hi };
}
void add(int x, int a, int b) { // add x to [a,b]
update(1, 0, SZ - 1, a, b, x);
}
void update(int node, int l, int r, int a, int b, int x) {
if (l > b || r < a) return;
if (l >= a && r <= b) {
data[node].insert(x);
return;
}
int mid = (l + r) / 2;
update(node * 2, l, mid, a, b, x);
update(node * 2 + 1, mid + 1, r, a, b, x);
}
};
SegmentTree<17> htree, vtree;
void test() {
htree.init(0, 10);
htree.add(6, 1, 3);
htree.add(2, 1, 4);
cout << htree.query(2, 3).first << " " << htree.query(2, 3).second << "\n";
cout << htree.query(0, 6).first << " " << htree.query(0, 6).second << "\n";
htree.add(8, 0, 2);
cout << htree.query(1, 1).first << " " << htree.query(1, 1).second << "\n";
cout << htree.query(3, 9).first << " " << htree.query(3, 9).second << "\n";
}
int main() {
io();
// test();
int a, b;
cin >> a >> b;
htree.init(0, b);
vtree.init(0, a);
int n;
cin >> n;
FOR(i, 0, n) {
int x, y, d;
cin >> x >> y >> d;
pll yb = htree.query(x, y); // {ymin, ymax}
pll xb = vtree.query(y, x); // {xmin, xmax}
pll area;
if (d == 1) { // build horizontal
area = { (xb.second - xb.first)*(y - yb.first), (xb.second - xb.first)*(yb.second - y) };
htree.add(y, xb.first, xb.second);
}
else { // build vertical
area = { (yb.second - yb.first)*(x - xb.first), (yb.second - yb.first)*(xb.second - x) };
vtree.add(x, yb.first, yb.second);
}
if (area.first > area.second) swap(area.first, area.second);
cout << area.first << " " << area.second << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
109 ms |
74360 KB |
Output is correct |
2 |
Correct |
105 ms |
74596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
74828 KB |
Output is correct |
2 |
Correct |
117 ms |
75236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
474 ms |
88592 KB |
Output is correct |
2 |
Correct |
346 ms |
100256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
437 ms |
100256 KB |
Output is correct |
2 |
Correct |
402 ms |
101880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
423 ms |
101880 KB |
Output is correct |
2 |
Correct |
502 ms |
124052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
505 ms |
124052 KB |
Output is correct |
2 |
Correct |
580 ms |
127032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1073 ms |
127032 KB |
Output is correct |
2 |
Correct |
641 ms |
132304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1134 ms |
132304 KB |
Output is correct |
2 |
Correct |
541 ms |
132304 KB |
Output is correct |
3 |
Correct |
406 ms |
132304 KB |
Output is correct |
4 |
Correct |
576 ms |
139544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
940 ms |
139544 KB |
Output is correct |
2 |
Correct |
497 ms |
139544 KB |
Output is correct |
3 |
Correct |
451 ms |
139544 KB |
Output is correct |
4 |
Correct |
849 ms |
159568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1031 ms |
159568 KB |
Output is correct |
2 |
Correct |
501 ms |
159568 KB |
Output is correct |
3 |
Correct |
458 ms |
159568 KB |
Output is correct |
4 |
Correct |
859 ms |
164324 KB |
Output is correct |