답안 #832920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832920 2023-08-21T16:43:39 Z mat_jur 사다리꼴 (balkan11_trapezoid) C++17
100 / 100
166 ms 16832 KB
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << "," << p.second << ")"; return o;}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";for(auto e:x)o<< e << ", ";return o<<"}";}
#define debug(X) cerr << "["#X"]:" << X << '\n';
#else 
#define debug(X) ;
#endif
#define ll long long
#define trapez tuple<int, int, int, int, int>

int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen("trapezoid.in", "r", stdin);
//	freopen("trapezoid.out", "w", stdout);

	int n;
	cin >> n;
	vector<tuple<int, int, int, int, int>> v;
	map<int, int> M;
	for (int i = 0; i < n; i++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		v.emplace_back(make_tuple(a, b, c, d, i));
		M[c]; M[d];
	}
	M[0];
	int x = 0;
	for (auto &e : M) {
		e.second = x++;
	}
	x--;
	sort(v.begin(), v.end());
	auto cmp = [&](trapez a, trapez b) {return get<1>(a) > get<1>(b);};
	priority_queue<trapez, vector<trapez>, decltype(cmp)> Q(cmp);
	vector<pair<int, int>> dp(n);
	pair<int, int> res = {0, 0};

	int base = 1;
	while (base < x) base *= 2;
	vector<pair<int, int>> tree(2*base);
	const int mod = 30013;
	auto merge = [&](pair<int, int> a, pair<int, int> b) {
		if (a.first == b.first) return make_pair(a.first, (b.second+a.second)%mod);
		if (a.first > b.first) return a;
		else return b;
	};
	auto update = [&](int v, pair<int, int> x) {
		v += base;
		while (v > 0) {
			tree[v] = merge(tree[v], x);
			v /= 2;
		}
	};
	auto query = [&](int a, int b) {
		a += base-1;
		b += base+1;
		pair<int, int> res = {0, 0};
		while (a/2 != b/2) {
			if (a%2 == 0) res = merge(res, tree[a+1]);
			if (b%2 == 1) res = merge(res, tree[b-1]);
			a /= 2; b /= 2;
		}
		return res;
	};
	for (auto &[a, b, c, d, idx] : v) {
		while (!Q.empty() && get<1>(Q.top()) < a) {
			update(M[get<3>(Q.top())], dp[get<4>(Q.top())]);
			Q.pop();
		}
		dp[idx] = query(0, M[c]);
		dp[idx].first++;
		if (dp[idx].first == 1) dp[idx].second = 1;
		res = merge(res, dp[idx]);
		Q.push(make_tuple(a, b, c, d, idx));
	}
	
	cout << res.first << ' ' << res.second << '\n';

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 4 ms 1024 KB Output is correct
8 Correct 6 ms 1164 KB Output is correct
9 Correct 11 ms 2096 KB Output is correct
10 Correct 20 ms 3820 KB Output is correct
11 Correct 28 ms 4472 KB Output is correct
12 Correct 85 ms 8544 KB Output is correct
13 Correct 98 ms 9768 KB Output is correct
14 Correct 91 ms 13012 KB Output is correct
15 Correct 166 ms 13784 KB Output is correct
16 Correct 130 ms 14556 KB Output is correct
17 Correct 138 ms 15128 KB Output is correct
18 Correct 157 ms 15392 KB Output is correct
19 Correct 129 ms 16172 KB Output is correct
20 Correct 149 ms 16832 KB Output is correct