# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
469211 |
2021-08-31T06:17:26 Z |
Millad |
LIS (INOI20_lis) |
C++14 |
|
2518 ms |
217964 KB |
/// In the name of god
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#define F first
#define S second
#define pb push_back
#define debug(x) cerr << #x << " : " << x << '\n'
using namespace std;
typedef int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
const ll maxn = 1e6 + 5;
ll q, x[maxn], p[maxn], b[maxn], ind[maxn], seg[maxn * 4], dp[maxn], lis;
set <ll> A[maxn], B[maxn];
vector <ll> Qu;
inline ll get_ind(ll id, ll ps = 0, ll v = 1, ll s = 0, ll e = q){
if(e - s == 1){
seg[v] = 1;
return s;
}
ll mid = (e + s) >> 1, lc = v << 1, rc = lc | 1, ind;
if(ps + (mid - s) - seg[lc] < id)ind = get_ind(id, ps + (mid - s) - seg[lc], rc, mid, e);
else ind = get_ind(id, ps, lc, s, mid);
seg[v] = seg[lc] + seg[rc];
return ind;
}
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> q;
for(ll i = 0; i < q; i ++)cin >> p[i] >> x[i];
for(ll i = q - 1; i >= 0; i --){
ind[i] = get_ind(p[i]);
b[ind[i]] = x[i];
}
set<ll>::iterator pnt;
for(ll i = 0; i < q; i ++){
ll id = ind[i], d = 0;
A[x[i]].insert(id);
for(ll j = 1; j < x[i]; j ++){
if(A[j].empty())continue;
if(*A[j].begin() > id)continue;
if(*A[j].rbegin() < id){
d = max(d, dp[*A[j].rbegin()]);
continue;
}
pnt = A[j].upper_bound(id);
pnt --; d = max(d, dp[*pnt]);
}
d ++;
dp[id] = d; B[d].insert(id);
Qu.pb(id); lis = max(lis, d);
while(Qu.size()){
ll id2 = Qu.back(); Qu.pop_back();
pnt = B[dp[id2]].lower_bound(id2);
vector <ll> vec;
while(true){
pnt ++;
if(pnt == B[dp[id2]].end())break;
if(b[*pnt] < b[id2])break;
if(b[*pnt] == b[id2])break;
vec.pb(*pnt);
}
for(ll j : vec){
B[dp[j]].erase(j);
dp[j] ++; lis = max(lis, dp[j]);
B[dp[j]].insert(j); Qu.pb(j);
}
}
cout << lis << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
94284 KB |
Output is correct |
2 |
Correct |
53 ms |
94212 KB |
Output is correct |
3 |
Correct |
60 ms |
94460 KB |
Output is correct |
4 |
Correct |
55 ms |
94408 KB |
Output is correct |
5 |
Correct |
74 ms |
94532 KB |
Output is correct |
6 |
Correct |
65 ms |
94516 KB |
Output is correct |
7 |
Correct |
78 ms |
94480 KB |
Output is correct |
8 |
Correct |
61 ms |
94404 KB |
Output is correct |
9 |
Correct |
57 ms |
94540 KB |
Output is correct |
10 |
Correct |
59 ms |
94524 KB |
Output is correct |
11 |
Correct |
65 ms |
94460 KB |
Output is correct |
12 |
Correct |
61 ms |
94404 KB |
Output is correct |
13 |
Correct |
63 ms |
94440 KB |
Output is correct |
14 |
Correct |
76 ms |
94404 KB |
Output is correct |
15 |
Correct |
58 ms |
94472 KB |
Output is correct |
16 |
Correct |
59 ms |
94416 KB |
Output is correct |
17 |
Correct |
60 ms |
94436 KB |
Output is correct |
18 |
Correct |
63 ms |
94520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
94284 KB |
Output is correct |
2 |
Correct |
53 ms |
94212 KB |
Output is correct |
3 |
Correct |
60 ms |
94460 KB |
Output is correct |
4 |
Correct |
55 ms |
94408 KB |
Output is correct |
5 |
Correct |
74 ms |
94532 KB |
Output is correct |
6 |
Correct |
65 ms |
94516 KB |
Output is correct |
7 |
Correct |
78 ms |
94480 KB |
Output is correct |
8 |
Correct |
61 ms |
94404 KB |
Output is correct |
9 |
Correct |
57 ms |
94540 KB |
Output is correct |
10 |
Correct |
59 ms |
94524 KB |
Output is correct |
11 |
Correct |
65 ms |
94460 KB |
Output is correct |
12 |
Correct |
61 ms |
94404 KB |
Output is correct |
13 |
Correct |
63 ms |
94440 KB |
Output is correct |
14 |
Correct |
76 ms |
94404 KB |
Output is correct |
15 |
Correct |
58 ms |
94472 KB |
Output is correct |
16 |
Correct |
59 ms |
94416 KB |
Output is correct |
17 |
Correct |
60 ms |
94436 KB |
Output is correct |
18 |
Correct |
63 ms |
94520 KB |
Output is correct |
19 |
Correct |
217 ms |
117328 KB |
Output is correct |
20 |
Correct |
274 ms |
117448 KB |
Output is correct |
21 |
Correct |
533 ms |
117848 KB |
Output is correct |
22 |
Correct |
653 ms |
117496 KB |
Output is correct |
23 |
Correct |
425 ms |
117404 KB |
Output is correct |
24 |
Correct |
546 ms |
117536 KB |
Output is correct |
25 |
Correct |
446 ms |
117488 KB |
Output is correct |
26 |
Correct |
468 ms |
117524 KB |
Output is correct |
27 |
Correct |
466 ms |
117408 KB |
Output is correct |
28 |
Correct |
467 ms |
117548 KB |
Output is correct |
29 |
Correct |
532 ms |
117480 KB |
Output is correct |
30 |
Correct |
444 ms |
117440 KB |
Output is correct |
31 |
Correct |
1008 ms |
117484 KB |
Output is correct |
32 |
Correct |
834 ms |
117400 KB |
Output is correct |
33 |
Correct |
738 ms |
117480 KB |
Output is correct |
34 |
Correct |
738 ms |
117520 KB |
Output is correct |
35 |
Correct |
766 ms |
117564 KB |
Output is correct |
36 |
Correct |
823 ms |
117412 KB |
Output is correct |
37 |
Correct |
787 ms |
117372 KB |
Output is correct |
38 |
Correct |
748 ms |
117488 KB |
Output is correct |
39 |
Correct |
734 ms |
117416 KB |
Output is correct |
40 |
Correct |
730 ms |
117604 KB |
Output is correct |
41 |
Correct |
182 ms |
112960 KB |
Output is correct |
42 |
Correct |
82 ms |
97768 KB |
Output is correct |
43 |
Correct |
385 ms |
112888 KB |
Output is correct |
44 |
Correct |
326 ms |
106664 KB |
Output is correct |
45 |
Correct |
78 ms |
96156 KB |
Output is correct |
46 |
Correct |
59 ms |
94660 KB |
Output is correct |
47 |
Correct |
156 ms |
102948 KB |
Output is correct |
48 |
Correct |
119 ms |
100212 KB |
Output is correct |
49 |
Correct |
64 ms |
95664 KB |
Output is correct |
50 |
Correct |
56 ms |
94572 KB |
Output is correct |
51 |
Correct |
109 ms |
99660 KB |
Output is correct |
52 |
Correct |
246 ms |
109020 KB |
Output is correct |
53 |
Correct |
207 ms |
106820 KB |
Output is correct |
54 |
Correct |
242 ms |
105536 KB |
Output is correct |
55 |
Correct |
88 ms |
97004 KB |
Output is correct |
56 |
Correct |
232 ms |
103660 KB |
Output is correct |
57 |
Correct |
133 ms |
98260 KB |
Output is correct |
58 |
Correct |
109 ms |
97976 KB |
Output is correct |
59 |
Correct |
67 ms |
95176 KB |
Output is correct |
60 |
Correct |
335 ms |
107588 KB |
Output is correct |
61 |
Correct |
80 ms |
94416 KB |
Output is correct |
62 |
Correct |
163 ms |
100748 KB |
Output is correct |
63 |
Correct |
103 ms |
97764 KB |
Output is correct |
64 |
Correct |
246 ms |
104160 KB |
Output is correct |
65 |
Correct |
201 ms |
103048 KB |
Output is correct |
66 |
Correct |
98 ms |
96696 KB |
Output is correct |
67 |
Correct |
190 ms |
101036 KB |
Output is correct |
68 |
Correct |
131 ms |
98928 KB |
Output is correct |
69 |
Correct |
224 ms |
103052 KB |
Output is correct |
70 |
Correct |
79 ms |
96220 KB |
Output is correct |
71 |
Correct |
2505 ms |
217888 KB |
Output is correct |
72 |
Correct |
2374 ms |
217964 KB |
Output is correct |
73 |
Correct |
2368 ms |
217900 KB |
Output is correct |
74 |
Correct |
2518 ms |
217844 KB |
Output is correct |
75 |
Correct |
2352 ms |
217924 KB |
Output is correct |
76 |
Correct |
2450 ms |
217948 KB |
Output is correct |