Submission #470433

# Submission time Handle Problem Language Result Execution time Memory
470433 2021-09-03T18:30:52 Z sinamhdv LIS (INOI20_lis) C++11
100 / 100
2601 ms 222236 KB
// INOI20_lis
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;

#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define fast_io ios::sync_with_stdio(0); cin.tie(0);
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int MAXN = 1000100;
const int LOGN = 25;

int n;
int qp[MAXN], qx[MAXN];
int fen[MAXN];
int pos[MAXN];
int val[MAXN];
set<int> apos[MAXN], dppos[MAXN];
int dp[MAXN];
int ans = 0;

inline void add(int i, int x)
{
	for (i++; i < MAXN; i += i & -i) fen[i] += x;
}

inline int fenbs(int x)
{
	int sum = 0, ptr = 0;
	for (int i = LOGN - 1; i >= 0; i--)
	{
		int nd = ptr + (1 << i);
		if (nd < MAXN - 5 && sum + fen[nd] < x) sum += fen[nd], ptr = nd;
	}
	return ptr;
}

void updatedp(int v)
{
	ans = max(ans, dp[v]);

	auto it = dppos[dp[v]].upper_bound(v);
	vector<set<int>::iterator> vec;
	while (it != dppos[dp[v]].end() && val[*it] > val[v])
		vec.pb(it), it++;
	for (auto it : vec)
	{
		int u = *it;
		dppos[dp[v]].erase(it);
		dppos[dp[v] + 1].insert(u);
		dp[u]++;
		updatedp(u);
	}
}

int32_t main(void)
{
	fast_io;
	cin >> n;
	FOR(i, 0, n) cin >> qp[i] >> qx[i];
	FOR(i, 0, n) add(i, 1);
	for (int i = n - 1; i >= 0; i--)
	{
		pos[i] = fenbs(qp[i]);
		add(pos[i], -1);
		val[pos[i]] = qx[i];
	}

	dbgr(pos, pos + n);
	dbgr(val, val + n);

	FOR(i, 0, n)
	{
		int x = qx[i], p = pos[i];
		for (int j = x - 1; j >= 0; j--)
		{
			auto it = apos[j].lower_bound(p);
			if (it == apos[j].begin()) continue;
			it--;
			dp[p] = max(dp[p], dp[*it]);
		}
		dp[p]++;

		apos[x].insert(p);
		dppos[dp[p]].insert(p);
		updatedp(p);

		dbgr(dp, dp + n);

		cout << ans << endl;
	}

	return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 54 ms 94272 KB Output is correct
2 Correct 48 ms 94224 KB Output is correct
3 Correct 54 ms 94476 KB Output is correct
4 Correct 54 ms 94516 KB Output is correct
5 Correct 66 ms 94636 KB Output is correct
6 Correct 59 ms 94516 KB Output is correct
7 Correct 56 ms 94516 KB Output is correct
8 Correct 63 ms 94580 KB Output is correct
9 Correct 61 ms 94512 KB Output is correct
10 Correct 57 ms 94536 KB Output is correct
11 Correct 57 ms 94608 KB Output is correct
12 Correct 56 ms 94576 KB Output is correct
13 Correct 61 ms 94524 KB Output is correct
14 Correct 59 ms 94512 KB Output is correct
15 Correct 58 ms 94552 KB Output is correct
16 Correct 58 ms 94496 KB Output is correct
17 Correct 59 ms 94608 KB Output is correct
18 Correct 59 ms 94504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 94272 KB Output is correct
2 Correct 48 ms 94224 KB Output is correct
3 Correct 54 ms 94476 KB Output is correct
4 Correct 54 ms 94516 KB Output is correct
5 Correct 66 ms 94636 KB Output is correct
6 Correct 59 ms 94516 KB Output is correct
7 Correct 56 ms 94516 KB Output is correct
8 Correct 63 ms 94580 KB Output is correct
9 Correct 61 ms 94512 KB Output is correct
10 Correct 57 ms 94536 KB Output is correct
11 Correct 57 ms 94608 KB Output is correct
12 Correct 56 ms 94576 KB Output is correct
13 Correct 61 ms 94524 KB Output is correct
14 Correct 59 ms 94512 KB Output is correct
15 Correct 58 ms 94552 KB Output is correct
16 Correct 58 ms 94496 KB Output is correct
17 Correct 59 ms 94608 KB Output is correct
18 Correct 59 ms 94504 KB Output is correct
19 Correct 360 ms 117576 KB Output is correct
20 Correct 367 ms 117736 KB Output is correct
21 Correct 425 ms 116740 KB Output is correct
22 Correct 588 ms 116952 KB Output is correct
23 Correct 379 ms 117628 KB Output is correct
24 Correct 380 ms 117700 KB Output is correct
25 Correct 384 ms 117576 KB Output is correct
26 Correct 381 ms 117628 KB Output is correct
27 Correct 378 ms 117528 KB Output is correct
28 Correct 380 ms 117572 KB Output is correct
29 Correct 380 ms 117516 KB Output is correct
30 Correct 381 ms 117556 KB Output is correct
31 Correct 581 ms 117692 KB Output is correct
32 Correct 667 ms 117480 KB Output is correct
33 Correct 615 ms 117600 KB Output is correct
34 Correct 593 ms 117576 KB Output is correct
35 Correct 584 ms 117680 KB Output is correct
36 Correct 642 ms 117472 KB Output is correct
37 Correct 597 ms 117660 KB Output is correct
38 Correct 624 ms 117596 KB Output is correct
39 Correct 607 ms 117700 KB Output is correct
40 Correct 625 ms 117584 KB Output is correct
41 Correct 281 ms 112676 KB Output is correct
42 Correct 86 ms 97836 KB Output is correct
43 Correct 340 ms 111572 KB Output is correct
44 Correct 321 ms 106436 KB Output is correct
45 Correct 70 ms 96256 KB Output is correct
46 Correct 57 ms 94672 KB Output is correct
47 Correct 145 ms 102784 KB Output is correct
48 Correct 114 ms 100344 KB Output is correct
49 Correct 64 ms 95712 KB Output is correct
50 Correct 56 ms 94636 KB Output is correct
51 Correct 107 ms 99720 KB Output is correct
52 Correct 236 ms 109384 KB Output is correct
53 Correct 198 ms 107012 KB Output is correct
54 Correct 180 ms 105588 KB Output is correct
55 Correct 78 ms 97092 KB Output is correct
56 Correct 195 ms 103520 KB Output is correct
57 Correct 110 ms 98400 KB Output is correct
58 Correct 104 ms 97844 KB Output is correct
59 Correct 64 ms 95300 KB Output is correct
60 Correct 315 ms 107824 KB Output is correct
61 Correct 52 ms 94504 KB Output is correct
62 Correct 161 ms 100796 KB Output is correct
63 Correct 105 ms 98012 KB Output is correct
64 Correct 254 ms 103976 KB Output is correct
65 Correct 198 ms 102892 KB Output is correct
66 Correct 88 ms 96692 KB Output is correct
67 Correct 166 ms 101104 KB Output is correct
68 Correct 120 ms 98828 KB Output is correct
69 Correct 200 ms 102768 KB Output is correct
70 Correct 79 ms 96356 KB Output is correct
71 Correct 2541 ms 222048 KB Output is correct
72 Correct 2601 ms 222128 KB Output is correct
73 Correct 2534 ms 222236 KB Output is correct
74 Correct 2475 ms 222184 KB Output is correct
75 Correct 2447 ms 222200 KB Output is correct
76 Correct 2398 ms 222004 KB Output is correct