답안 #999535

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
999535 2024-06-15T17:42:00 Z vjudge1 LIS (INOI20_lis) C++17
100 / 100
1550 ms 143952 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define inf 0x3F3F3F3F3F3F3F3F

struct DSU
{
	vector<int> e;
	void init(int n)
	{
		e.assign(n + 1, -1);
	}
	int get(int x)
	{
		if (e[x] < 0) return x;
		return e[x] = get(e[x]);
	}
	void unite(int x, int y)
	{
		x = get(x), y = get(y);
		if (x == y) return;
		if (e[x] > e[y]) swap(x, y);
		e[x] += e[y];
		e[y] = x;
	}
};
struct BIT
{
	int n;
	vector<int> ft;
	void init(int N)
	{
		n = N + 5;
		ft.assign(n + 5, 0);
	}
	void add(int pos, int val)
	{
		for (pos = pos + 1; pos <= n; pos += pos & -pos) ft[pos] += val;
 	}
	int get(int pos, int res = 0)
	{
		for (pos = pos + 1; pos > 0; pos -= pos & -pos) res += ft[pos];
		return res;
	}
};

const int MXN = 1e6 + 5;

set<int> st[MXN];
int res[MXN], v[MXN];
int ans = 0;

void add(int i)
{
	ans = max(ans, res[i]);
	auto it = st[res[i]].begin();
	while ((it = st[res[i]].upper_bound(i)) != st[res[i]].end() && v[*it] > v[i])
	{
		int x = *it;
		st[res[i]].erase(it);
		res[x] = res[i] + 1;
		add(x);
	}
	st[res[i]].insert(i);
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	array<int, 2> a[n];
	for (array<int, 2> &i : a) cin >> i[0] >> i[1];
	BIT ft;
	ft.init(n);
	for (int i = n - 1; i >= 0; i--)
	{
		int l = 1, r = n;
		while (l < r)
		{
			int mid = (l + r) >> 1;
			if (mid - ft.get(mid) >= a[i][0]) r = mid;
			else l = mid + 1;
		}
		a[i][0] = l;
		v[l] = a[i][1];
		ft.add(l, 1);
	}
	for (array<int, 2> &i : a)
	{
		res[i[0]] = 1;
		for (int j = 1; j < i[1]; j++)
		{
			auto it = st[j].lower_bound(i[0]);
			if (!(it == st[j].begin() || v[*prev(it)] >= i[1])) res[i[0]] = j + 1;
		}
		add(i[0]);
		cout << ans << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 50520 KB Output is correct
2 Correct 8 ms 50524 KB Output is correct
3 Correct 11 ms 50616 KB Output is correct
4 Correct 12 ms 50524 KB Output is correct
5 Correct 16 ms 50524 KB Output is correct
6 Correct 15 ms 50700 KB Output is correct
7 Correct 13 ms 50776 KB Output is correct
8 Correct 12 ms 50776 KB Output is correct
9 Correct 12 ms 50604 KB Output is correct
10 Correct 13 ms 50628 KB Output is correct
11 Correct 12 ms 50776 KB Output is correct
12 Correct 15 ms 50640 KB Output is correct
13 Correct 16 ms 50776 KB Output is correct
14 Correct 15 ms 50524 KB Output is correct
15 Correct 13 ms 50700 KB Output is correct
16 Correct 14 ms 50720 KB Output is correct
17 Correct 14 ms 50524 KB Output is correct
18 Correct 15 ms 50768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 50520 KB Output is correct
2 Correct 8 ms 50524 KB Output is correct
3 Correct 11 ms 50616 KB Output is correct
4 Correct 12 ms 50524 KB Output is correct
5 Correct 16 ms 50524 KB Output is correct
6 Correct 15 ms 50700 KB Output is correct
7 Correct 13 ms 50776 KB Output is correct
8 Correct 12 ms 50776 KB Output is correct
9 Correct 12 ms 50604 KB Output is correct
10 Correct 13 ms 50628 KB Output is correct
11 Correct 12 ms 50776 KB Output is correct
12 Correct 15 ms 50640 KB Output is correct
13 Correct 16 ms 50776 KB Output is correct
14 Correct 15 ms 50524 KB Output is correct
15 Correct 13 ms 50700 KB Output is correct
16 Correct 14 ms 50720 KB Output is correct
17 Correct 14 ms 50524 KB Output is correct
18 Correct 15 ms 50768 KB Output is correct
19 Correct 170 ms 69432 KB Output is correct
20 Correct 161 ms 69524 KB Output is correct
21 Correct 212 ms 68820 KB Output is correct
22 Correct 274 ms 68832 KB Output is correct
23 Correct 193 ms 69400 KB Output is correct
24 Correct 176 ms 69460 KB Output is correct
25 Correct 169 ms 69456 KB Output is correct
26 Correct 180 ms 69504 KB Output is correct
27 Correct 174 ms 69484 KB Output is correct
28 Correct 176 ms 69460 KB Output is correct
29 Correct 178 ms 69424 KB Output is correct
30 Correct 170 ms 69460 KB Output is correct
31 Correct 288 ms 69460 KB Output is correct
32 Correct 294 ms 69460 KB Output is correct
33 Correct 288 ms 69460 KB Output is correct
34 Correct 289 ms 69652 KB Output is correct
35 Correct 293 ms 69460 KB Output is correct
36 Correct 292 ms 69496 KB Output is correct
37 Correct 304 ms 69484 KB Output is correct
38 Correct 293 ms 69456 KB Output is correct
39 Correct 287 ms 69396 KB Output is correct
40 Correct 295 ms 69712 KB Output is correct
41 Correct 140 ms 66384 KB Output is correct
42 Correct 26 ms 55008 KB Output is correct
43 Correct 164 ms 65548 KB Output is correct
44 Correct 149 ms 62152 KB Output is correct
45 Correct 18 ms 51800 KB Output is correct
46 Correct 12 ms 50620 KB Output is correct
47 Correct 60 ms 58188 KB Output is correct
48 Correct 43 ms 56400 KB Output is correct
49 Correct 16 ms 51548 KB Output is correct
50 Correct 11 ms 50776 KB Output is correct
51 Correct 39 ms 56016 KB Output is correct
52 Correct 107 ms 64336 KB Output is correct
53 Correct 90 ms 62860 KB Output is correct
54 Correct 77 ms 61908 KB Output is correct
55 Correct 23 ms 52304 KB Output is correct
56 Correct 101 ms 60660 KB Output is correct
57 Correct 46 ms 55380 KB Output is correct
58 Correct 37 ms 54868 KB Output is correct
59 Correct 15 ms 51036 KB Output is correct
60 Correct 159 ms 63272 KB Output is correct
61 Correct 10 ms 50524 KB Output is correct
62 Correct 68 ms 56708 KB Output is correct
63 Correct 41 ms 54872 KB Output is correct
64 Correct 109 ms 60932 KB Output is correct
65 Correct 91 ms 58196 KB Output is correct
66 Correct 31 ms 52048 KB Output is correct
67 Correct 77 ms 56912 KB Output is correct
68 Correct 48 ms 55544 KB Output is correct
69 Correct 89 ms 58028 KB Output is correct
70 Correct 24 ms 51796 KB Output is correct
71 Correct 1546 ms 143952 KB Output is correct
72 Correct 1383 ms 143952 KB Output is correct
73 Correct 1417 ms 143952 KB Output is correct
74 Correct 1481 ms 143720 KB Output is correct
75 Correct 1394 ms 143700 KB Output is correct
76 Correct 1550 ms 143952 KB Output is correct