#pragma GCC optimize("Ofast,unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef int ll;
typedef long double ld;
typedef pair <ll, ll> pll;
#ifdef SINA
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; }
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); }
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1); cout.flush();
#else
#define dbg(...) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< (x) << endl, 0
#define cl const ll
#define fr first
#define sc second
#define lc (v << 1)
#define rc (lc | 1)
#define mid ((l + r) >> 1)
#define All(x) (x).begin(), (x).end()
cl inf = sizeof(ll) == 4 ? (1e9 + 10) : (3e18), mod = 1e9 + 7, MOD = 998244353;
template <class A,class B> ostream& operator << (ostream& out,const pair<A,B>&a){return out<<'('<<a.first<<", "<<a.second<<')';}
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
out<< '['; for (int i = -1; ++i < int(a.size());) out<< a[i] << (i + 1 < int(a.size()) ? ", " : ""); return out<<']'; }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;
cl N = 1e6 + 7;
ll P [N], X [N], a [N], b [N], lis [N], n, ans;
set <ll> pos [N], dpos [N];
struct fenwick {
ll fen [N];
inline fenwick () { for (ll i = 1; i < N; i++) add(i, 1); }
inline void add (ll i, cl &x) { for (; i < N; i += i & -i) fen[i] += x; }
inline ll kth (ll x) {
ll ret = 0;
for (ll i = 20; i--;) if (ret + (1 << i) < N && fen[ret + (1 << i)] < x) ret += 1 << i, x -= fen[ret];
add(ret + 1, -1); return ret + 1;
}
} fen;
void upd (cl &i) {
ans = max(ans, lis[i]);
for (auto it = dpos[lis[i]].lower_bound(a[i]); it != dpos[lis[i]].end() && X[i] < X[b[*it]];) {
lis[b[*it]]++; upd(b[*it]);
dpos[lis[i] + 1].insert(*it); it++;
dpos[lis[i]].erase(prev(it));
}
}
int main ()
{
cin.tie(0)->sync_with_stdio(false);
cin>> n;
for (ll i = 1; i <= n; i++) cin>> P[i] >> X[i];
for (ll i = n; i; i--) b[a[i] = fen.kth(P[i])] = i;
for (ll i = 1; i <= n; i++) {
for (ll j = X[i]; --j;) {
auto it = pos[j].lower_bound(a[i]);
if (it != pos[j].begin()) lis[i] = max(lis[i], lis[b[*prev(it)]]);
}
lis[i]++;
upd(i);
pos[X[i]].insert(a[i]);
dpos[lis[i]].insert(a[i]);
cout<< ans << '\n';
}
cerr<< "\n" __TIMESTAMP__ " - Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
/*
6
1 7
2 10
2 11
2 8
4 10
1 2
4
1 3
2 1
1 1
2 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
98252 KB |
Output is correct |
2 |
Correct |
76 ms |
98156 KB |
Output is correct |
3 |
Correct |
85 ms |
98404 KB |
Output is correct |
4 |
Correct |
93 ms |
98448 KB |
Output is correct |
5 |
Correct |
91 ms |
98436 KB |
Output is correct |
6 |
Correct |
94 ms |
98364 KB |
Output is correct |
7 |
Correct |
85 ms |
98352 KB |
Output is correct |
8 |
Correct |
85 ms |
98380 KB |
Output is correct |
9 |
Correct |
93 ms |
98336 KB |
Output is correct |
10 |
Correct |
86 ms |
98428 KB |
Output is correct |
11 |
Correct |
86 ms |
98404 KB |
Output is correct |
12 |
Correct |
85 ms |
98540 KB |
Output is correct |
13 |
Correct |
104 ms |
98372 KB |
Output is correct |
14 |
Correct |
94 ms |
98396 KB |
Output is correct |
15 |
Correct |
89 ms |
98440 KB |
Output is correct |
16 |
Correct |
94 ms |
98356 KB |
Output is correct |
17 |
Correct |
101 ms |
98324 KB |
Output is correct |
18 |
Correct |
88 ms |
98372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
98252 KB |
Output is correct |
2 |
Correct |
76 ms |
98156 KB |
Output is correct |
3 |
Correct |
85 ms |
98404 KB |
Output is correct |
4 |
Correct |
93 ms |
98448 KB |
Output is correct |
5 |
Correct |
91 ms |
98436 KB |
Output is correct |
6 |
Correct |
94 ms |
98364 KB |
Output is correct |
7 |
Correct |
85 ms |
98352 KB |
Output is correct |
8 |
Correct |
85 ms |
98380 KB |
Output is correct |
9 |
Correct |
93 ms |
98336 KB |
Output is correct |
10 |
Correct |
86 ms |
98428 KB |
Output is correct |
11 |
Correct |
86 ms |
98404 KB |
Output is correct |
12 |
Correct |
85 ms |
98540 KB |
Output is correct |
13 |
Correct |
104 ms |
98372 KB |
Output is correct |
14 |
Correct |
94 ms |
98396 KB |
Output is correct |
15 |
Correct |
89 ms |
98440 KB |
Output is correct |
16 |
Correct |
94 ms |
98356 KB |
Output is correct |
17 |
Correct |
101 ms |
98324 KB |
Output is correct |
18 |
Correct |
88 ms |
98372 KB |
Output is correct |
19 |
Correct |
403 ms |
120708 KB |
Output is correct |
20 |
Correct |
394 ms |
120752 KB |
Output is correct |
21 |
Correct |
489 ms |
119916 KB |
Output is correct |
22 |
Correct |
603 ms |
120008 KB |
Output is correct |
23 |
Correct |
431 ms |
120732 KB |
Output is correct |
24 |
Correct |
450 ms |
120688 KB |
Output is correct |
25 |
Correct |
453 ms |
120744 KB |
Output is correct |
26 |
Correct |
505 ms |
120792 KB |
Output is correct |
27 |
Correct |
455 ms |
120656 KB |
Output is correct |
28 |
Correct |
457 ms |
120816 KB |
Output is correct |
29 |
Correct |
445 ms |
120804 KB |
Output is correct |
30 |
Correct |
482 ms |
120732 KB |
Output is correct |
31 |
Correct |
844 ms |
120692 KB |
Output is correct |
32 |
Correct |
761 ms |
120752 KB |
Output is correct |
33 |
Correct |
681 ms |
120700 KB |
Output is correct |
34 |
Correct |
660 ms |
120740 KB |
Output is correct |
35 |
Correct |
722 ms |
120772 KB |
Output is correct |
36 |
Correct |
685 ms |
120848 KB |
Output is correct |
37 |
Correct |
685 ms |
120652 KB |
Output is correct |
38 |
Correct |
726 ms |
120828 KB |
Output is correct |
39 |
Correct |
680 ms |
120728 KB |
Output is correct |
40 |
Correct |
692 ms |
120732 KB |
Output is correct |
41 |
Correct |
326 ms |
115972 KB |
Output is correct |
42 |
Correct |
115 ms |
101652 KB |
Output is correct |
43 |
Correct |
344 ms |
114944 KB |
Output is correct |
44 |
Correct |
324 ms |
109860 KB |
Output is correct |
45 |
Correct |
99 ms |
100036 KB |
Output is correct |
46 |
Correct |
83 ms |
98572 KB |
Output is correct |
47 |
Correct |
179 ms |
106404 KB |
Output is correct |
48 |
Correct |
145 ms |
103992 KB |
Output is correct |
49 |
Correct |
94 ms |
99540 KB |
Output is correct |
50 |
Correct |
83 ms |
98516 KB |
Output is correct |
51 |
Correct |
138 ms |
103428 KB |
Output is correct |
52 |
Correct |
279 ms |
112764 KB |
Output is correct |
53 |
Correct |
241 ms |
110404 KB |
Output is correct |
54 |
Correct |
220 ms |
109024 KB |
Output is correct |
55 |
Correct |
112 ms |
100804 KB |
Output is correct |
56 |
Correct |
257 ms |
107056 KB |
Output is correct |
57 |
Correct |
141 ms |
102060 KB |
Output is correct |
58 |
Correct |
135 ms |
101672 KB |
Output is correct |
59 |
Correct |
92 ms |
99136 KB |
Output is correct |
60 |
Correct |
353 ms |
111312 KB |
Output is correct |
61 |
Correct |
84 ms |
98376 KB |
Output is correct |
62 |
Correct |
192 ms |
104516 KB |
Output is correct |
63 |
Correct |
133 ms |
101652 KB |
Output is correct |
64 |
Correct |
254 ms |
107584 KB |
Output is correct |
65 |
Correct |
232 ms |
106584 KB |
Output is correct |
66 |
Correct |
117 ms |
100528 KB |
Output is correct |
67 |
Correct |
190 ms |
104772 KB |
Output is correct |
68 |
Correct |
155 ms |
102564 KB |
Output is correct |
69 |
Correct |
221 ms |
106308 KB |
Output is correct |
70 |
Correct |
107 ms |
100200 KB |
Output is correct |
71 |
Correct |
2359 ms |
222116 KB |
Output is correct |
72 |
Correct |
2349 ms |
222060 KB |
Output is correct |
73 |
Correct |
2462 ms |
222032 KB |
Output is correct |
74 |
Correct |
2409 ms |
222100 KB |
Output is correct |
75 |
Correct |
2333 ms |
222108 KB |
Output is correct |
76 |
Correct |
2393 ms |
222072 KB |
Output is correct |