#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define vc vector
#define pb push_back
#define fr first
#define sc second
#define Heh ios::sync_with_stdio(false) , cin.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
const int MAXN = 1e6 + 16 , s = 1 << 20 , sq = 1.5e3 + 15.3;
int n , b[MAXN] , a[MAXN] , it[MAXN] , lis[MAXN] , ans;
set<int> lit[sq];
set<int>::iterator iter;
int segTree[s<<1] , lazy[s<<1];
inline void shift(int v){
segTree[v<<1] += lazy[v];
segTree[(v<<1)^1] += lazy[v];
lazy[v<<1] += lazy[v];
lazy[(v<<1)^1] += lazy[v];
lazy[v] = 0;
}
int get(int v , int tl , int tr){
if(tl == tr) return tl;
shift(v);
int mid = (tl + tr) >> 1;
if(segTree[(v<<1)^1] == 0) return get((v<<1)^1 , mid+1 , tr);
return get((v<<1) , tl , mid);
}
void upd(int v , int tl , int tr , int l , int r , int x){
if(l > tr or r < tl) return;
if(l <= tl and r >= tr){
segTree[v] += x;
lazy[v] += x;
return;
}
shift(v);
int mid = (tl + tr) >> 1;
upd(v<<1 , tl , mid , l , r , x);
upd((v<<1)^1 , mid+1 , tr , l , r , x);
segTree[v] = min(segTree[v<<1] , segTree[(v<<1)^1]);
}
void upd(int id){
set<int>::iterator iter = lit[lis[id]].lower_bound(id);
while(1){
if(iter != lit[lis[id]].end() and a[*iter] > a[id]){
int jd = *iter;
iter++;
lit[lis[id]].erase(jd);
lis[jd]++;
upd(jd);
}
else break;
}
lit[lis[id]].insert(id);
ans = max(ans , lis[id]);
}
int c;
void read(int& ans){
ans = 0;
c = getchar();
while(c >= 48 and c < 58){
ans = 10 * ans + c - 48;
c = getchar();
}
}
int main(){
for(int i = 0 ; i < (s<<1) ; i++) segTree[i] = MAXN;
read(n);
for(int i = 0 ; i < n ; i++){
int id;
read(id) , read(b[i]);
id--;
segTree[s+i] = i-id;
}
for(int i = s-1 ; i >= 1 ; i--){
segTree[i] = min(segTree[i<<1] , segTree[(i<<1)^1]);
}
for(int i = 0 ; i < n ; i++){
int id = get(1 , 0 , s-1);
a[n-i-1] = b[id];
it[id] = n-i-1;
upd(1 , 0 , s-1 , id , n-1 , -1);
upd(1 , 0 , s-1 , id , id , MAXN);
}
for(int i = 0 ; i < n ; i++){
int id = it[i];
lis[id] = 1;
while(1){
iter = lit[lis[id]].lower_bound(id);
if(iter != lit[lis[id]].begin() and a[*(--iter)] < a[id]) lis[id]++;
else break;
}
upd(id);
printf("%d\n" , ans);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8652 KB |
Output is correct |
2 |
Correct |
6 ms |
8652 KB |
Output is correct |
3 |
Correct |
9 ms |
8796 KB |
Output is correct |
4 |
Correct |
9 ms |
8780 KB |
Output is correct |
5 |
Correct |
20 ms |
8740 KB |
Output is correct |
6 |
Correct |
14 ms |
8744 KB |
Output is correct |
7 |
Correct |
13 ms |
8724 KB |
Output is correct |
8 |
Correct |
12 ms |
8744 KB |
Output is correct |
9 |
Correct |
13 ms |
8732 KB |
Output is correct |
10 |
Correct |
11 ms |
8780 KB |
Output is correct |
11 |
Correct |
12 ms |
8780 KB |
Output is correct |
12 |
Correct |
11 ms |
8780 KB |
Output is correct |
13 |
Correct |
13 ms |
8780 KB |
Output is correct |
14 |
Correct |
15 ms |
8760 KB |
Output is correct |
15 |
Correct |
11 ms |
8780 KB |
Output is correct |
16 |
Correct |
13 ms |
8700 KB |
Output is correct |
17 |
Correct |
14 ms |
8728 KB |
Output is correct |
18 |
Correct |
13 ms |
8692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8652 KB |
Output is correct |
2 |
Correct |
6 ms |
8652 KB |
Output is correct |
3 |
Correct |
9 ms |
8796 KB |
Output is correct |
4 |
Correct |
9 ms |
8780 KB |
Output is correct |
5 |
Correct |
20 ms |
8740 KB |
Output is correct |
6 |
Correct |
14 ms |
8744 KB |
Output is correct |
7 |
Correct |
13 ms |
8724 KB |
Output is correct |
8 |
Correct |
12 ms |
8744 KB |
Output is correct |
9 |
Correct |
13 ms |
8732 KB |
Output is correct |
10 |
Correct |
11 ms |
8780 KB |
Output is correct |
11 |
Correct |
12 ms |
8780 KB |
Output is correct |
12 |
Correct |
11 ms |
8780 KB |
Output is correct |
13 |
Correct |
13 ms |
8780 KB |
Output is correct |
14 |
Correct |
15 ms |
8760 KB |
Output is correct |
15 |
Correct |
11 ms |
8780 KB |
Output is correct |
16 |
Correct |
13 ms |
8700 KB |
Output is correct |
17 |
Correct |
14 ms |
8728 KB |
Output is correct |
18 |
Correct |
13 ms |
8692 KB |
Output is correct |
19 |
Correct |
409 ms |
21772 KB |
Output is correct |
20 |
Correct |
352 ms |
21908 KB |
Output is correct |
21 |
Correct |
485 ms |
21800 KB |
Output is correct |
22 |
Correct |
526 ms |
22044 KB |
Output is correct |
23 |
Correct |
424 ms |
22084 KB |
Output is correct |
24 |
Correct |
436 ms |
21956 KB |
Output is correct |
25 |
Correct |
411 ms |
22096 KB |
Output is correct |
26 |
Correct |
419 ms |
21956 KB |
Output is correct |
27 |
Correct |
456 ms |
21964 KB |
Output is correct |
28 |
Correct |
424 ms |
21960 KB |
Output is correct |
29 |
Correct |
435 ms |
21976 KB |
Output is correct |
30 |
Correct |
429 ms |
22064 KB |
Output is correct |
31 |
Correct |
597 ms |
22004 KB |
Output is correct |
32 |
Correct |
571 ms |
21916 KB |
Output is correct |
33 |
Correct |
600 ms |
21980 KB |
Output is correct |
34 |
Correct |
644 ms |
21980 KB |
Output is correct |
35 |
Correct |
590 ms |
22040 KB |
Output is correct |
36 |
Correct |
628 ms |
21924 KB |
Output is correct |
37 |
Correct |
596 ms |
22108 KB |
Output is correct |
38 |
Correct |
590 ms |
22048 KB |
Output is correct |
39 |
Correct |
598 ms |
21876 KB |
Output is correct |
40 |
Correct |
585 ms |
22052 KB |
Output is correct |
41 |
Correct |
313 ms |
19012 KB |
Output is correct |
42 |
Correct |
54 ms |
10712 KB |
Output is correct |
43 |
Correct |
367 ms |
18840 KB |
Output is correct |
44 |
Correct |
270 ms |
15692 KB |
Output is correct |
45 |
Correct |
33 ms |
9780 KB |
Output is correct |
46 |
Correct |
12 ms |
8828 KB |
Output is correct |
47 |
Correct |
134 ms |
13424 KB |
Output is correct |
48 |
Correct |
96 ms |
12116 KB |
Output is correct |
49 |
Correct |
25 ms |
9420 KB |
Output is correct |
50 |
Correct |
12 ms |
8780 KB |
Output is correct |
51 |
Correct |
88 ms |
11768 KB |
Output is correct |
52 |
Correct |
246 ms |
17284 KB |
Output is correct |
53 |
Correct |
207 ms |
15844 KB |
Output is correct |
54 |
Correct |
179 ms |
15040 KB |
Output is correct |
55 |
Correct |
43 ms |
10180 KB |
Output is correct |
56 |
Correct |
195 ms |
13868 KB |
Output is correct |
57 |
Correct |
82 ms |
10888 KB |
Output is correct |
58 |
Correct |
70 ms |
10688 KB |
Output is correct |
59 |
Correct |
25 ms |
9196 KB |
Output is correct |
60 |
Correct |
302 ms |
16540 KB |
Output is correct |
61 |
Correct |
9 ms |
8780 KB |
Output is correct |
62 |
Correct |
160 ms |
12324 KB |
Output is correct |
63 |
Correct |
68 ms |
10712 KB |
Output is correct |
64 |
Correct |
203 ms |
14312 KB |
Output is correct |
65 |
Correct |
180 ms |
13764 KB |
Output is correct |
66 |
Correct |
48 ms |
10004 KB |
Output is correct |
67 |
Correct |
136 ms |
12520 KB |
Output is correct |
68 |
Correct |
90 ms |
11204 KB |
Output is correct |
69 |
Correct |
177 ms |
13468 KB |
Output is correct |
70 |
Correct |
42 ms |
9812 KB |
Output is correct |
71 |
Correct |
2642 ms |
81108 KB |
Output is correct |
72 |
Correct |
2754 ms |
80924 KB |
Output is correct |
73 |
Correct |
2673 ms |
81152 KB |
Output is correct |
74 |
Correct |
2667 ms |
81016 KB |
Output is correct |
75 |
Correct |
2721 ms |
81024 KB |
Output is correct |
76 |
Correct |
2652 ms |
81224 KB |
Output is correct |