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 <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
pi operator+(pi x, pi y){
return {max(x.f, y.f), min(x.s, y.s)};
}
const int inf = 0x3f3f3f3f;
struct segTree{
int l, r;
segTree *left, *right;
set<int> s;
segTree(int a, int b){
l = a, r = b;
s.insert(-inf);
s.insert(inf);
if(l != r){
int mid = (l + r) / 2;
left = new segTree(l, mid);
right = new segTree(mid + 1, r);
}
}
pi amt(int x){
auto it = s.lower_bound(x);
return {*it == x ? x :*prev(it), *it};
}
void add(int a, int b, int v){
if(b < l || r < a) return;
if(a <= l && r <= b){
s.insert(v);
return;
}
left->add(a, b, v);
right->add(a, b, v);
}
pi qry(int x, int y){
if(x < l || r < x) return {-inf, inf};
if(l == r) return amt(y);
return left->qry(x, y) + amt(y) + right->qry(x, y);
}
};
const int mxn = 100000;
int n[2], q;
segTree *tre[2];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n[0] >> n[1] >> q;
for(int i = 0; i < 2; i++){
tre[i] = new segTree(0, n[!i]);
for(int j = 0; j < 2; j++){
tre[i]->add(0, n[!i], n[i] * j);
}
}
while(q--){
ll t, x[2], r[2];
cin >> x[0] >> x[1] >> t;
t--;
pi p[2];
for(int i = 0; i < 2; i++){
p[i] = tre[i]->qry(x[!i], x[i]);
}
for(int i = 0; i < 2; i++){
r[i] = (p[t].s - p[t].f) * abs(x[!t] - p[!t].f);
swap(p[!t].f, p[!t].s);
}
tre[!t]->add(p[t].f, p[t].s, x[!t]);
sort(r, r + 2);
cout << r[0] << " " << r[1] << endl;
}
return 0;
}
# | 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... |