#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define lwb lower_bound
#define upb upper_bound
#define TASKNAME "NAME"
void init()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
///freopen(TASKNAME".INP","r",stdin); freopen(TASKNAME".OUT","w",stdout);
}
const int SZ = 1e5+5;
const ll INF = INT_MAX / 2, MOD = 1e9+7, INFLL = 2e18;
const double epsilon = 1e-3;
int a,b,n;
struct SegTree
{
set<int> nodes[4*SZ];
void update(int id, int lo, int hi, int u, int v, int val)
{
if(hi < u || lo > v) return;
if(lo >= u && hi <= v)
{
nodes[id].insert(val);
//cout << "update " << lo << " " << hi << " " << val << '\n';
return;
}
int mid = (lo + hi) / 2;
update(2*id, lo, mid, u , v, val);
update(2*id+1, mid+1, hi, u, v, val);
}
pii query(int id, int lo, int hi, int x, int y)
{
pii res;
auto it1 = nodes[id].lower_bound(y);
if(it1 == nodes[id].begin())
{
res = { (it1 == nodes[id].end() ? INF : *it1), -INF};
} else
{
auto it2 = it1;
it2--;
res = { (it1 == nodes[id].end() ? INF : *it1) , *it2};
}
//cout << "query " << lo << " " << hi << " " << res.fi << " " << res.se << '\n';
if(lo == hi) return res;
int mid = (lo + hi) / 2;
pii cur;
if(x <= mid) cur = query(2*id, lo, mid, x, y);
else cur = query(2*id+1, mid+1, hi, x, y);
return {min(res.fi, cur.fi), max(res.se, cur.se) };
}
};
SegTree seg1, seg2;
int main()
{
init();
cin >> a >> b;
seg1.update(1, 1, a, 1, a, 0);
seg1.update(1, 1 ,a, 1, a, b);
seg2.update(1, 1, b, 1, b, 0);
seg2.update(1, 1, b, 1, b, a);
cin >> n;
//n = 1;
for(int i = 1; i <= n; i++)
{
int x,y,d;
cin >> x >> y >> d;
pii cur1 = seg1.query(1, 1, a, x, y);
pii cur2 = seg2.query(1, 1, b, y, x);
ll a1 = cur1.fi - cur1.se, a2 = cur2.fi - cur2.se;
//cout << cur1.fi << " " << cur1.se << " - " << cur2.fi << " " << cur2.se << '\n';
if(d == 1)
{
ll res1 = a2 * (cur1.fi - y), res2 = a2 * (y - cur1.se);
cout << min(res1, res2) << " " << max(res1, res2) << '\n';
seg1.update(1, 1, a, cur2.se, cur2.fi, y);
} else
{
ll res1 = a1 * (cur2.fi - x), res2 = a1 * (x - cur2.se);
cout << min(res1, res2) << " " << max(res1, res2) << '\n';
seg2.update(1, 1, b, cur1.se, cur1.fi, x);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
37976 KB |
Output is correct |
2 |
Correct |
16 ms |
37980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
38276 KB |
Output is correct |
2 |
Correct |
24 ms |
38748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
43348 KB |
Output is correct |
2 |
Correct |
65 ms |
43348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
43376 KB |
Output is correct |
2 |
Correct |
77 ms |
44112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
43512 KB |
Output is correct |
2 |
Correct |
78 ms |
44936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
52304 KB |
Output is correct |
2 |
Correct |
171 ms |
66896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
382 ms |
67284 KB |
Output is correct |
2 |
Correct |
202 ms |
71508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
354 ms |
66388 KB |
Output is correct |
2 |
Correct |
205 ms |
76372 KB |
Output is correct |
3 |
Correct |
92 ms |
45500 KB |
Output is correct |
4 |
Correct |
229 ms |
73820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
412 ms |
67408 KB |
Output is correct |
2 |
Correct |
234 ms |
80208 KB |
Output is correct |
3 |
Correct |
79 ms |
45652 KB |
Output is correct |
4 |
Correct |
225 ms |
76116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
435 ms |
67648 KB |
Output is correct |
2 |
Correct |
181 ms |
70568 KB |
Output is correct |
3 |
Correct |
89 ms |
45816 KB |
Output is correct |
4 |
Correct |
240 ms |
78284 KB |
Output is correct |