답안 #37584

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
37584 2017-12-26T08:24:21 Z szawinis 사다리꼴 (balkan11_trapezoid) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 19, MOD = 30013;

struct query {
	int r, type, swp, idx;
};

int n, a[N], b[N], c[N], d[N], dp[N], f[N];
vector<query> segs[N];

void compress() {
	vector<int> cc;
	unordered_map<int, int> pos;
	for(int i = 1; i <= n; i++) {
		cc.push_back(a[i]);
		cc.push_back(b[i]);
		cc.push_back(c[i]);
		cc.push_back(d[i]);
	}
	sort(cc.begin(), cc.end());
	cc.resize(distance(cc.begin(), unique(cc.begin(), cc.end())));
	for(int i = 0; i < cc.size(); i++) pos[cc[i]] = i+1;
	for(int i = 1; i <= n; i++) {
		a[i] = pos[a[i]];
		b[i] = pos[b[i]];
		c[i] = pos[c[i]];
		d[i] = pos[d[i]];
	}
	// cout << cc.size() << endl;
}

pair<int,int> merge(pair<int,int> p1, pair<int,int> p2) {
	if(p1.first > p2.first) return p1;
	else if(p2.first > p1.first) return p2;
	else return {p1.first, (p1.second + p2.second) % MOD};
}

struct segtree {
	pair<int,int> t[2*N];

	void update(int i, int sz, int cnt) {
		i += N;
		t[i] = merge(make_pair(sz, cnt), t[i]);
		for(i >>= 1; i >= 1; i >>= 1) t[i] = merge(t[i<<1], t[i<<1|1]);
	}

	pair<int,int> query(int l, int r) { // [)
		pair<int,int> res = {INT_MIN, 0};
		for(l += N, r += N; l < r; l >>= 1, r >>= 1) {
			if(l & 1) res = merge(res, t[l++]);
			if(r & 1) res = merge(res, t[--r]);
		}
		return res;
	}
} t[2];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
	compress();
	for(int i = 1; i <= n; i++) {
		if(a[i] <= c[i]) {
			segs[a[i]].push_back({c[i], 0, 0, i});
			segs[b[i]].push_back({d[i], 1, 0, i});
		} else {
			segs[c[i]].push_back({a[i], 0, 1, i});
			segs[d[i]].push_back({b[i], 1, 1, i});
		}
	}
	fill(t[0].t, t[0].t+2*N, make_pair(INT_MIN, 0));
	fill(t[1].t, t[1].t+2*N, make_pair(INT_MIN, 0));
	t[0].update(0, 0, 1);
	t[1].update(0, 0, 1);
	for(int l = 1; l < N; l++) {
		for(auto qq: segs[l]) {
			if(!qq.type) {
				pair<int,int> res[2] = {t[qq.swp].query(0, qq.r), t[qq.swp ^ 1].query(0, l)};
				tie(dp[qq.idx], f[qq.idx]) = merge(res[0], res[1]);
				if(!dp[qq.idx]) f[qq.idx] = 1;
				++dp[qq.idx];
			} else {
				t[qq.swp].update(qq.r, dp[qq.idx], f[qq.idx]);
			}
			// cout << l << ' ' << qq.r << ' ' << qq.type << ' ' << qq.swp << ' ' << qq.idx << ' ' << dp[qq.idx] << ' ' << f[qq.idx] << endl;
		}
	}
	pair<int,int> ans = merge(t[0].query(0, N), t[1].query(0, N));
	printf("%d %d", ans.first, ans.second);
}

Compilation message

Compilation timeout while compiling trapezoid