Submission #832835

# Submission time Handle Problem Language Result Execution time Memory
832835 2023-08-21T15:53:34 Z mat_jur trapezoid (balkan11_trapezoid) C++17
0 / 100
114 ms 20628 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<int> dp(n);
	int res = 0;

	int base = 1;
	while (base < x) base *= 2;
	vector<int> tree(2*base);
	auto update = [&](int v, int x) {
		v += base;
		while (v > 0) {
			tree[v] = max(tree[v], x);
			v /= 2;
		}
	};
	auto query = [&](int a, int b) {
		a += base-1;
		b += base+1;
		int res = 0;
		while (a/2 != b/2) {
			if (a%2 == 0) res = max(res, tree[a+1]);
			if (b%2 == 1) res = max(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])+1;
		res = max(res, dp[idx]);
		Q.push(make_tuple(a, b, c, d, idx));
	}
	
	cout << res;

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 320 KB Unexpected end of file - int32 expected
2 Incorrect 0 ms 340 KB Unexpected end of file - int32 expected
3 Incorrect 1 ms 340 KB Unexpected end of file - int32 expected
4 Incorrect 1 ms 468 KB Unexpected end of file - int32 expected
5 Incorrect 2 ms 596 KB Unexpected end of file - int32 expected
6 Incorrect 3 ms 852 KB Unexpected end of file - int32 expected
7 Incorrect 3 ms 1100 KB Unexpected end of file - int32 expected
8 Incorrect 5 ms 1364 KB Unexpected end of file - int32 expected
9 Incorrect 9 ms 2404 KB Unexpected end of file - int32 expected
10 Incorrect 17 ms 4664 KB Unexpected end of file - int32 expected
11 Incorrect 29 ms 5364 KB Unexpected end of file - int32 expected
12 Incorrect 62 ms 10396 KB Unexpected end of file - int32 expected
13 Incorrect 61 ms 11896 KB Unexpected end of file - int32 expected
14 Incorrect 68 ms 16308 KB Unexpected end of file - int32 expected
15 Incorrect 78 ms 17036 KB Unexpected end of file - int32 expected
16 Incorrect 91 ms 17708 KB Unexpected end of file - int32 expected
17 Incorrect 90 ms 18444 KB Unexpected end of file - int32 expected
18 Incorrect 83 ms 19100 KB Unexpected end of file - int32 expected
19 Incorrect 114 ms 17120 KB Unexpected end of file - int32 expected
20 Incorrect 106 ms 20628 KB Unexpected end of file - int32 expected