# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
999537 |
2024-06-15T17:43:46 Z |
aykhn |
LIS (INOI20_lis) |
C++17 |
|
1861 ms |
135508 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 |
16 ms |
48476 KB |
Output is correct |
2 |
Correct |
16 ms |
48332 KB |
Output is correct |
3 |
Correct |
22 ms |
48476 KB |
Output is correct |
4 |
Correct |
19 ms |
48532 KB |
Output is correct |
5 |
Correct |
30 ms |
48472 KB |
Output is correct |
6 |
Correct |
22 ms |
48732 KB |
Output is correct |
7 |
Correct |
23 ms |
48728 KB |
Output is correct |
8 |
Correct |
17 ms |
50524 KB |
Output is correct |
9 |
Correct |
13 ms |
50672 KB |
Output is correct |
10 |
Correct |
22 ms |
48728 KB |
Output is correct |
11 |
Correct |
20 ms |
48728 KB |
Output is correct |
12 |
Correct |
24 ms |
48476 KB |
Output is correct |
13 |
Correct |
22 ms |
48476 KB |
Output is correct |
14 |
Correct |
24 ms |
48732 KB |
Output is correct |
15 |
Correct |
22 ms |
48476 KB |
Output is correct |
16 |
Correct |
30 ms |
48712 KB |
Output is correct |
17 |
Correct |
21 ms |
48476 KB |
Output is correct |
18 |
Correct |
27 ms |
48476 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
48476 KB |
Output is correct |
2 |
Correct |
16 ms |
48332 KB |
Output is correct |
3 |
Correct |
22 ms |
48476 KB |
Output is correct |
4 |
Correct |
19 ms |
48532 KB |
Output is correct |
5 |
Correct |
30 ms |
48472 KB |
Output is correct |
6 |
Correct |
22 ms |
48732 KB |
Output is correct |
7 |
Correct |
23 ms |
48728 KB |
Output is correct |
8 |
Correct |
17 ms |
50524 KB |
Output is correct |
9 |
Correct |
13 ms |
50672 KB |
Output is correct |
10 |
Correct |
22 ms |
48728 KB |
Output is correct |
11 |
Correct |
20 ms |
48728 KB |
Output is correct |
12 |
Correct |
24 ms |
48476 KB |
Output is correct |
13 |
Correct |
22 ms |
48476 KB |
Output is correct |
14 |
Correct |
24 ms |
48732 KB |
Output is correct |
15 |
Correct |
22 ms |
48476 KB |
Output is correct |
16 |
Correct |
30 ms |
48712 KB |
Output is correct |
17 |
Correct |
21 ms |
48476 KB |
Output is correct |
18 |
Correct |
27 ms |
48476 KB |
Output is correct |
19 |
Correct |
175 ms |
67912 KB |
Output is correct |
20 |
Correct |
151 ms |
68180 KB |
Output is correct |
21 |
Correct |
215 ms |
68024 KB |
Output is correct |
22 |
Correct |
284 ms |
66644 KB |
Output is correct |
23 |
Correct |
186 ms |
66672 KB |
Output is correct |
24 |
Correct |
183 ms |
65364 KB |
Output is correct |
25 |
Correct |
181 ms |
65532 KB |
Output is correct |
26 |
Correct |
209 ms |
68024 KB |
Output is correct |
27 |
Correct |
181 ms |
67920 KB |
Output is correct |
28 |
Correct |
179 ms |
68180 KB |
Output is correct |
29 |
Correct |
179 ms |
68084 KB |
Output is correct |
30 |
Correct |
183 ms |
68020 KB |
Output is correct |
31 |
Correct |
288 ms |
68080 KB |
Output is correct |
32 |
Correct |
333 ms |
68076 KB |
Output is correct |
33 |
Correct |
291 ms |
68064 KB |
Output is correct |
34 |
Correct |
322 ms |
68100 KB |
Output is correct |
35 |
Correct |
298 ms |
68176 KB |
Output is correct |
36 |
Correct |
319 ms |
68020 KB |
Output is correct |
37 |
Correct |
308 ms |
68088 KB |
Output is correct |
38 |
Correct |
326 ms |
68028 KB |
Output is correct |
39 |
Correct |
311 ms |
65360 KB |
Output is correct |
40 |
Correct |
315 ms |
65360 KB |
Output is correct |
41 |
Correct |
141 ms |
63576 KB |
Output is correct |
42 |
Correct |
33 ms |
54648 KB |
Output is correct |
43 |
Correct |
168 ms |
61928 KB |
Output is correct |
44 |
Correct |
143 ms |
58656 KB |
Output is correct |
45 |
Correct |
19 ms |
51800 KB |
Output is correct |
46 |
Correct |
16 ms |
50776 KB |
Output is correct |
47 |
Correct |
60 ms |
54468 KB |
Output is correct |
48 |
Correct |
47 ms |
56268 KB |
Output is correct |
49 |
Correct |
25 ms |
48220 KB |
Output is correct |
50 |
Correct |
20 ms |
47704 KB |
Output is correct |
51 |
Correct |
42 ms |
55892 KB |
Output is correct |
52 |
Correct |
151 ms |
57940 KB |
Output is correct |
53 |
Correct |
104 ms |
56148 KB |
Output is correct |
54 |
Correct |
108 ms |
61112 KB |
Output is correct |
55 |
Correct |
35 ms |
49244 KB |
Output is correct |
56 |
Correct |
141 ms |
53784 KB |
Output is correct |
57 |
Correct |
55 ms |
51284 KB |
Output is correct |
58 |
Correct |
49 ms |
54716 KB |
Output is correct |
59 |
Correct |
19 ms |
49248 KB |
Output is correct |
60 |
Correct |
180 ms |
56656 KB |
Output is correct |
61 |
Correct |
27 ms |
47544 KB |
Output is correct |
62 |
Correct |
73 ms |
54700 KB |
Output is correct |
63 |
Correct |
41 ms |
54876 KB |
Output is correct |
64 |
Correct |
120 ms |
60396 KB |
Output is correct |
65 |
Correct |
116 ms |
57488 KB |
Output is correct |
66 |
Correct |
29 ms |
52052 KB |
Output is correct |
67 |
Correct |
76 ms |
56660 KB |
Output is correct |
68 |
Correct |
56 ms |
55380 KB |
Output is correct |
69 |
Correct |
100 ms |
57672 KB |
Output is correct |
70 |
Correct |
31 ms |
51812 KB |
Output is correct |
71 |
Correct |
1806 ms |
135324 KB |
Output is correct |
72 |
Correct |
1861 ms |
135356 KB |
Output is correct |
73 |
Correct |
1809 ms |
135432 KB |
Output is correct |
74 |
Correct |
1604 ms |
135508 KB |
Output is correct |
75 |
Correct |
1777 ms |
135508 KB |
Output is correct |
76 |
Correct |
1837 ms |
135488 KB |
Output is correct |