답안 #627149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627149 2022-08-12T09:16:47 Z NothingXD LIS (INOI20_lis) C++14
100 / 100
1883 ms 120520 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << H;
	debug_out(T...);
}

#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
#define F first
#define S second

const int MAXN = 1e6 + 10;
const int LOG = 20;
int n, f[MAXN], a[MAXN], x[MAXN], Q[MAXN];
set<int> st[MAXN];

void add(int idx, int x){
	for (; idx <= n; idx += idx & -idx) f[idx] += x;
}

int find(int x){
	int idx = 0;
	for (int i = LOG-1; ~i; i--){
		if (idx + (1 << i) <= n && f[idx + (1 << i)] < x){
			idx += (1 << i);
			x -= f[idx];
		}
	}
	return idx + 1;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);

	cin >> n;

	for (int i = 1; i <= n; i++){
		cin >> x[i] >> a[i];
		add(i, 1);
	}

	for (int i = n; i; i--){
		int ptr = find(x[i]);
		x[i] = ptr;
		Q[x[i]] = i;
		add(ptr, -1);
	}

	int ans = 0;
	st[0].insert(0);


	for (int i = 1; i <= n; i++){
		int cnt = 0;
		while(!st[cnt].empty()){
			auto it = st[cnt].lower_bound(x[i]);
			if (it == st[cnt].begin()) break;
			it--;
			if (a[Q[*it]] >= a[i]) break;
			cnt++;
		}
		queue<pii> q;
		q.push({x[i] , cnt});
		while(!q.empty()){
			int idx = q.front().F, ptr = q.front().S;
			q.pop();
			ans = max(ans, ptr);
			while(!st[ptr].empty()){
				auto it = st[ptr].lower_bound(idx);
				if (it == st[ptr].end()) break;
				if (a[Q[*it]] <= a[Q[idx]]) break;
				q.push({*it, ptr + 1});
				st[ptr].erase(it);
			}
			st[ptr].insert(idx);
		}
		cout << ans << '\n';
	}

}
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 47348 KB Output is correct
2 Correct 27 ms 47220 KB Output is correct
3 Correct 28 ms 47392 KB Output is correct
4 Correct 29 ms 47444 KB Output is correct
5 Correct 31 ms 47444 KB Output is correct
6 Correct 33 ms 47412 KB Output is correct
7 Correct 26 ms 47436 KB Output is correct
8 Correct 30 ms 47412 KB Output is correct
9 Correct 28 ms 47436 KB Output is correct
10 Correct 27 ms 47440 KB Output is correct
11 Correct 27 ms 47472 KB Output is correct
12 Correct 26 ms 47432 KB Output is correct
13 Correct 32 ms 47444 KB Output is correct
14 Correct 29 ms 47436 KB Output is correct
15 Correct 31 ms 47408 KB Output is correct
16 Correct 30 ms 47368 KB Output is correct
17 Correct 28 ms 47444 KB Output is correct
18 Correct 28 ms 47444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 47348 KB Output is correct
2 Correct 27 ms 47220 KB Output is correct
3 Correct 28 ms 47392 KB Output is correct
4 Correct 29 ms 47444 KB Output is correct
5 Correct 31 ms 47444 KB Output is correct
6 Correct 33 ms 47412 KB Output is correct
7 Correct 26 ms 47436 KB Output is correct
8 Correct 30 ms 47412 KB Output is correct
9 Correct 28 ms 47436 KB Output is correct
10 Correct 27 ms 47440 KB Output is correct
11 Correct 27 ms 47472 KB Output is correct
12 Correct 26 ms 47432 KB Output is correct
13 Correct 32 ms 47444 KB Output is correct
14 Correct 29 ms 47436 KB Output is correct
15 Correct 31 ms 47408 KB Output is correct
16 Correct 30 ms 47368 KB Output is correct
17 Correct 28 ms 47444 KB Output is correct
18 Correct 28 ms 47444 KB Output is correct
19 Correct 206 ms 60504 KB Output is correct
20 Correct 179 ms 60816 KB Output is correct
21 Correct 252 ms 59852 KB Output is correct
22 Correct 351 ms 59976 KB Output is correct
23 Correct 253 ms 60620 KB Output is correct
24 Correct 226 ms 60664 KB Output is correct
25 Correct 240 ms 60600 KB Output is correct
26 Correct 245 ms 60612 KB Output is correct
27 Correct 245 ms 60568 KB Output is correct
28 Correct 243 ms 60560 KB Output is correct
29 Correct 231 ms 60544 KB Output is correct
30 Correct 231 ms 60652 KB Output is correct
31 Correct 369 ms 60580 KB Output is correct
32 Correct 393 ms 60692 KB Output is correct
33 Correct 379 ms 60576 KB Output is correct
34 Correct 389 ms 60620 KB Output is correct
35 Correct 443 ms 60816 KB Output is correct
36 Correct 356 ms 60508 KB Output is correct
37 Correct 382 ms 60660 KB Output is correct
38 Correct 397 ms 60620 KB Output is correct
39 Correct 403 ms 60640 KB Output is correct
40 Correct 372 ms 60692 KB Output is correct
41 Correct 171 ms 57704 KB Output is correct
42 Correct 41 ms 49356 KB Output is correct
43 Correct 216 ms 56956 KB Output is correct
44 Correct 162 ms 54088 KB Output is correct
45 Correct 38 ms 48448 KB Output is correct
46 Correct 28 ms 47456 KB Output is correct
47 Correct 92 ms 52160 KB Output is correct
48 Correct 68 ms 50628 KB Output is correct
49 Correct 31 ms 48096 KB Output is correct
50 Correct 26 ms 47440 KB Output is correct
51 Correct 64 ms 50392 KB Output is correct
52 Correct 186 ms 55880 KB Output is correct
53 Correct 116 ms 54496 KB Output is correct
54 Correct 114 ms 53740 KB Output is correct
55 Correct 42 ms 48860 KB Output is correct
56 Correct 151 ms 52556 KB Output is correct
57 Correct 66 ms 49632 KB Output is correct
58 Correct 58 ms 49356 KB Output is correct
59 Correct 32 ms 47816 KB Output is correct
60 Correct 228 ms 54976 KB Output is correct
61 Correct 31 ms 47432 KB Output is correct
62 Correct 95 ms 51020 KB Output is correct
63 Correct 60 ms 49432 KB Output is correct
64 Correct 137 ms 52772 KB Output is correct
65 Correct 116 ms 52156 KB Output is correct
66 Correct 45 ms 48652 KB Output is correct
67 Correct 115 ms 51112 KB Output is correct
68 Correct 73 ms 49996 KB Output is correct
69 Correct 125 ms 52144 KB Output is correct
70 Correct 41 ms 48404 KB Output is correct
71 Correct 1831 ms 120400 KB Output is correct
72 Correct 1883 ms 120436 KB Output is correct
73 Correct 1854 ms 120448 KB Output is correct
74 Correct 1806 ms 120288 KB Output is correct
75 Correct 1795 ms 120520 KB Output is correct
76 Correct 1775 ms 120448 KB Output is correct