Submission #684854

# Submission time Handle Problem Language Result Execution time Memory
684854 2023-01-22T17:02:25 Z thiago_bastos trapezoid (balkan11_trapezoid) C++17
100 / 100
229 ms 25764 KB
#include "bits/stdc++.h"

using namespace std;

#define INF    1000000000
#define INFLL 1000000000000000000ll
#define EPS 1e-9
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define fi first
#define sc second

using i64 = long long;
using u64 = unsigned long long;
using ld = long double;
using ii = pair<int, int>;
using i128 = __int128;

const int MOD = 30013;

ii op(ii a, ii b) {
	if(a.fi != b.fi) return max(a, b);
	a.sc += b.sc;
	if(a.sc >= MOD) a.sc -= MOD;
	return a;
}

struct BIT2D {
	vector<vector<int>> Y;
	vector<int> X;
	vector<vector<ii>> bit;

	BIT2D() {}

	BIT2D(vector<ii> p) {
		for(auto [i, j] : p) X.pb(i);
		sort(all(X));
		X.resize(unique(all(X)) - X.begin());
		Y.resize(X.size() + 1);
		sort(all(p), [](auto a, auto b) {return a.sc < b.sc;});
		for(auto [i, j] : p) {
			for(int k = findPos(X, i); k < (int)Y.size(); k += k & -k)
				if(Y[k].empty() || Y[k].back() != j) Y[k].pb(j);
		}

		bit.resize(Y.size());
		for(int i = 0; i < (int)Y.size(); ++i) bit[i].assign(Y[i].size() + 1, ii(0, 0));
	}

	int findPos(vector<int>& coords, int v) {
		return upper_bound(all(coords), v) - coords.begin();
	}

	void upd(int i, int j, ii v) {
		for(int x = findPos(X, i); x < (int)bit.size(); x += x & -x)
			for(int y = findPos(Y[x], j); y < (int)bit[x].size(); y += y & -y)
				bit[x][y] = op(bit[x][y], v);
	}

	ii query(int i, int j) {
		ii ans = {0, 1};
		for(int x = findPos(X, i); x > 0; x -= x & -x)
			for(int y = findPos(Y[x], j); y > 0; y -= y & -y)
				ans = op(ans, bit[x][y]);
		return ans;
	}
};

void solve() {
	int n;

	cin >> n;

	vector<tuple<int, int, int, int>> t(n);
	vector<ii> query;

	for(auto& [a, b, c, d] : t) {
		cin >> a >> b >> c >> d;
		query.pb({b, d});
	}

	sort(all(t), [](auto p, auto q) {
		return min(get<0>(p), get<1>(p)) < min(get<0>(q), get<1>(q));
	});

	BIT2D bit(query);
	ii ans {};

	for(auto [a, b, c, d] : t) {
		auto [dp, cnt] = bit.query(a - 1, c - 1);
		++dp;
		bit.upd(b, d, {dp, cnt});
		ans = op(ans, {dp, cnt});
	}
	
	cout << ans.fi << ' ' << ans.sc << '\n';
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 5 ms 980 KB Output is correct
7 Correct 6 ms 1108 KB Output is correct
8 Correct 8 ms 1364 KB Output is correct
9 Correct 17 ms 2636 KB Output is correct
10 Correct 31 ms 5140 KB Output is correct
11 Correct 47 ms 6360 KB Output is correct
12 Correct 105 ms 12784 KB Output is correct
13 Correct 122 ms 15140 KB Output is correct
14 Correct 158 ms 18240 KB Output is correct
15 Correct 190 ms 19456 KB Output is correct
16 Correct 190 ms 20540 KB Output is correct
17 Correct 191 ms 21916 KB Output is correct
18 Correct 162 ms 23016 KB Output is correct
19 Correct 179 ms 24352 KB Output is correct
20 Correct 229 ms 25764 KB Output is correct