답안 #264770

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
264770 2020-08-14T09:19:42 Z super_j6 Krave (COI14_krave) C++14
100 / 100
1225 ms 111556 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 896 KB Output is correct
2 Correct 1 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 69752 KB Output is correct
2 Correct 95 ms 70068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 74744 KB Output is correct
2 Correct 184 ms 53880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 290 ms 74812 KB Output is correct
2 Correct 204 ms 61536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 287 ms 74776 KB Output is correct
2 Correct 233 ms 68992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 459 ms 83576 KB Output is correct
2 Correct 349 ms 77304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1133 ms 98040 KB Output is correct
2 Correct 431 ms 88908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1086 ms 97356 KB Output is correct
2 Correct 392 ms 107000 KB Output is correct
3 Correct 201 ms 45432 KB Output is correct
4 Correct 443 ms 94664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1225 ms 98480 KB Output is correct
2 Correct 444 ms 111556 KB Output is correct
3 Correct 230 ms 59268 KB Output is correct
4 Correct 484 ms 100280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1100 ms 98668 KB Output is correct
2 Correct 362 ms 97808 KB Output is correct
3 Correct 282 ms 76664 KB Output is correct
4 Correct 573 ms 105848 KB Output is correct