#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" , "O2" , "unroll-loops")
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];
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){
while(1){
iter = lit[lis[id]].lower_bound(id);
if(iter != lit[lis[id]].end() and a[*iter] > a[id]){
int jd = *iter;
lit[lis[id]].erase(iter);
lis[jd]++;
upd(jd);
}
else break;
}
lit[lis[id]].insert(id);
ans = max(ans , lis[id]);
}
int main(){
Heh;
for(int i = 0 ; i < (s<<1) ; i++) segTree[i] = MAXN;
cin >> n;
for(int i = 0 ; i < n ; i++){
int id;
cin >> id >> 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);
cout << ans << endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
8652 KB |
Output is correct |
2 |
Correct |
6 ms |
8652 KB |
Output is correct |
3 |
Correct |
14 ms |
8748 KB |
Output is correct |
4 |
Correct |
13 ms |
8748 KB |
Output is correct |
5 |
Correct |
23 ms |
8732 KB |
Output is correct |
6 |
Correct |
20 ms |
8740 KB |
Output is correct |
7 |
Correct |
20 ms |
8780 KB |
Output is correct |
8 |
Correct |
19 ms |
8780 KB |
Output is correct |
9 |
Correct |
18 ms |
8780 KB |
Output is correct |
10 |
Correct |
15 ms |
8712 KB |
Output is correct |
11 |
Correct |
17 ms |
8752 KB |
Output is correct |
12 |
Correct |
16 ms |
8716 KB |
Output is correct |
13 |
Correct |
17 ms |
8824 KB |
Output is correct |
14 |
Correct |
18 ms |
8820 KB |
Output is correct |
15 |
Correct |
16 ms |
8780 KB |
Output is correct |
16 |
Correct |
17 ms |
8756 KB |
Output is correct |
17 |
Correct |
17 ms |
8780 KB |
Output is correct |
18 |
Correct |
16 ms |
8780 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 |
14 ms |
8748 KB |
Output is correct |
4 |
Correct |
13 ms |
8748 KB |
Output is correct |
5 |
Correct |
23 ms |
8732 KB |
Output is correct |
6 |
Correct |
20 ms |
8740 KB |
Output is correct |
7 |
Correct |
20 ms |
8780 KB |
Output is correct |
8 |
Correct |
19 ms |
8780 KB |
Output is correct |
9 |
Correct |
18 ms |
8780 KB |
Output is correct |
10 |
Correct |
15 ms |
8712 KB |
Output is correct |
11 |
Correct |
17 ms |
8752 KB |
Output is correct |
12 |
Correct |
16 ms |
8716 KB |
Output is correct |
13 |
Correct |
17 ms |
8824 KB |
Output is correct |
14 |
Correct |
18 ms |
8820 KB |
Output is correct |
15 |
Correct |
16 ms |
8780 KB |
Output is correct |
16 |
Correct |
17 ms |
8756 KB |
Output is correct |
17 |
Correct |
17 ms |
8780 KB |
Output is correct |
18 |
Correct |
16 ms |
8780 KB |
Output is correct |
19 |
Correct |
761 ms |
21860 KB |
Output is correct |
20 |
Correct |
715 ms |
21960 KB |
Output is correct |
21 |
Correct |
807 ms |
21828 KB |
Output is correct |
22 |
Correct |
878 ms |
21920 KB |
Output is correct |
23 |
Correct |
809 ms |
21996 KB |
Output is correct |
24 |
Correct |
831 ms |
21988 KB |
Output is correct |
25 |
Correct |
804 ms |
22168 KB |
Output is correct |
26 |
Correct |
817 ms |
21912 KB |
Output is correct |
27 |
Correct |
807 ms |
22044 KB |
Output is correct |
28 |
Correct |
862 ms |
21920 KB |
Output is correct |
29 |
Correct |
813 ms |
21920 KB |
Output is correct |
30 |
Correct |
782 ms |
22028 KB |
Output is correct |
31 |
Correct |
988 ms |
22056 KB |
Output is correct |
32 |
Correct |
957 ms |
22012 KB |
Output is correct |
33 |
Correct |
979 ms |
22076 KB |
Output is correct |
34 |
Correct |
1066 ms |
22156 KB |
Output is correct |
35 |
Correct |
1020 ms |
22284 KB |
Output is correct |
36 |
Correct |
960 ms |
22064 KB |
Output is correct |
37 |
Correct |
998 ms |
22008 KB |
Output is correct |
38 |
Correct |
961 ms |
22004 KB |
Output is correct |
39 |
Correct |
951 ms |
21932 KB |
Output is correct |
40 |
Correct |
1033 ms |
22040 KB |
Output is correct |
41 |
Correct |
589 ms |
19168 KB |
Output is correct |
42 |
Correct |
111 ms |
10628 KB |
Output is correct |
43 |
Correct |
630 ms |
18828 KB |
Output is correct |
44 |
Correct |
458 ms |
15764 KB |
Output is correct |
45 |
Correct |
63 ms |
9716 KB |
Output is correct |
46 |
Correct |
18 ms |
8888 KB |
Output is correct |
47 |
Correct |
265 ms |
13540 KB |
Output is correct |
48 |
Correct |
192 ms |
12120 KB |
Output is correct |
49 |
Correct |
47 ms |
9400 KB |
Output is correct |
50 |
Correct |
18 ms |
8860 KB |
Output is correct |
51 |
Correct |
174 ms |
11744 KB |
Output is correct |
52 |
Correct |
500 ms |
17404 KB |
Output is correct |
53 |
Correct |
444 ms |
15900 KB |
Output is correct |
54 |
Correct |
359 ms |
15024 KB |
Output is correct |
55 |
Correct |
88 ms |
10180 KB |
Output is correct |
56 |
Correct |
347 ms |
13892 KB |
Output is correct |
57 |
Correct |
147 ms |
10992 KB |
Output is correct |
58 |
Correct |
127 ms |
10644 KB |
Output is correct |
59 |
Correct |
38 ms |
9164 KB |
Output is correct |
60 |
Correct |
532 ms |
16344 KB |
Output is correct |
61 |
Correct |
13 ms |
8780 KB |
Output is correct |
62 |
Correct |
236 ms |
12440 KB |
Output is correct |
63 |
Correct |
123 ms |
10720 KB |
Output is correct |
64 |
Correct |
387 ms |
14200 KB |
Output is correct |
65 |
Correct |
315 ms |
13584 KB |
Output is correct |
66 |
Correct |
88 ms |
9920 KB |
Output is correct |
67 |
Correct |
247 ms |
12676 KB |
Output is correct |
68 |
Correct |
160 ms |
11288 KB |
Output is correct |
69 |
Correct |
309 ms |
13508 KB |
Output is correct |
70 |
Correct |
89 ms |
9720 KB |
Output is correct |
71 |
Execution timed out |
4065 ms |
74104 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |