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;
void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
cerr << h; if(sizeof...(t)) cerr << ", ";
DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL
#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"
#define fi first
#define se second
using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
using db = long double;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
void setIO(string NAME = "") {
cin.tie(0)->sync_with_stdio(0);
if(sz(NAME)) {
freopen((NAME + ".inp").c_str(),"r",stdin);
freopen((NAME + ".out").c_str(),"w",stdout);
}
}
tcT> bool ckmin(T&a, const T&b) {
return b < a ? a=b,1 : 0; }
tcT> bool ckmax(T&a, const T&b) {
return b > a ? a=b,1 : 0; }
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int MX = 1e5+5;
struct SegTree {
set<int> seg[MX*4 + 7];
int N;
void init(int _SZ) {
N = _SZ;
}
void addPoint(int l, int r, int pos, int ind, int L, int R) {
if(l > R || r < L) return;
if(l <= L && R <= r) {
seg[ind].insert(pos);
return;
}
int mid = (L + R) >> 1;
addPoint(l, r, pos, ind<<1, L, mid);
addPoint(l, r, pos, ind<<1|1, mid+1, R);
}
void addPoint(int l, int r, int pos) {
addPoint(l, r, pos, 1, 0, N);
}
int query(int pos, int val, int ind, int L, int R) {
if(R < pos || pos < L) return -1;
auto it = seg[ind].upper_bound(val);
int res = -1;
if(it != seg[ind].begin()) {
it--;
res = *it;
}
if(L == R) return res;
int mid = (L + R) >> 1;
if(pos <= mid) ckmax(res, query(pos, val, ind<<1, L, mid));
else ckmax(res, query(pos, val, ind<<1|1, mid+1, R));
return res;
}
int query(int pos, int val) {
return query(pos, val, 1, 1, N);
}
};
struct Rect {
int xl, yl, xr, yr;
ll getArea() { return 1LL*(xr - xl)*(yr - yl); }
Rect(int _xl = 0, int _yl = 0, int _xr = 0, int _yr = 0) {
xl = _xl;
yl = _yl;
xr = _xr;
yr = _yr;
}
bool operator<(const Rect&rhs) const {
if(xl != rhs.xl) return xl < rhs.xl;
return yl < rhs.yl;
}
};
int A, B;
int N;
SegTree stX, stY;
set<Rect> s;
void solve() {
cin >> A >> B;
stY.init(A);
stX.init(B);
stY.addPoint(0, A, 0);
stX.addPoint(0, B, 0);
s.insert(Rect(0, 0, A, B));
cin >> N;
while(N-- > 0) {
int x, y, dir;
cin >> x >> y >> dir;
int rect_y = stY.query(x, y), rect_x = stX.query(y, x);
assert(rect_y > 0 && rect_x > 0);
auto it = s.lower_bound(Rect(rect_x, rect_y, -1, -1));
int xl = it->xl, yl = it->yl, xr = it->xr, yr = it->yr;
s.erase(it);
Rect newA, newB;
if(dir == 1) {
newA = Rect(xl, yl, xr, y);
newB = Rect(xl, y, xr, yr);
stY.addPoint(xl, xr, y);
}
else {
newA = Rect(xl, yl, x, yr);
newB = Rect(x, yl, xr, yr);
stX.addPoint(yl, yr, x);
}
cout << min(newA.getArea(), newB.getArea()) << " " << max(newA.getArea(), newB.getArea()) << nl;
s.insert(newA);
s.insert(newB);
}
}
int main() {
setIO();
int t=1;
//cin>>t;
while(t-->0) {
solve();
}
return 0;
}
Compilation message (stderr)
krave.cpp: In function 'void setIO(std::string)':
krave.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | freopen((NAME + ".inp").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
krave.cpp:41:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | freopen((NAME + ".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |