#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[*prev(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 |
8800 KB |
Output is correct |
4 |
Correct |
14 ms |
8740 KB |
Output is correct |
5 |
Correct |
22 ms |
8812 KB |
Output is correct |
6 |
Correct |
18 ms |
8780 KB |
Output is correct |
7 |
Correct |
17 ms |
8780 KB |
Output is correct |
8 |
Correct |
16 ms |
8780 KB |
Output is correct |
9 |
Correct |
16 ms |
8780 KB |
Output is correct |
10 |
Correct |
19 ms |
8780 KB |
Output is correct |
11 |
Correct |
16 ms |
8812 KB |
Output is correct |
12 |
Correct |
15 ms |
8712 KB |
Output is correct |
13 |
Correct |
17 ms |
8752 KB |
Output is correct |
14 |
Correct |
20 ms |
8820 KB |
Output is correct |
15 |
Correct |
16 ms |
8788 KB |
Output is correct |
16 |
Correct |
17 ms |
8908 KB |
Output is correct |
17 |
Correct |
17 ms |
8780 KB |
Output is correct |
18 |
Correct |
17 ms |
8808 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 |
8800 KB |
Output is correct |
4 |
Correct |
14 ms |
8740 KB |
Output is correct |
5 |
Correct |
22 ms |
8812 KB |
Output is correct |
6 |
Correct |
18 ms |
8780 KB |
Output is correct |
7 |
Correct |
17 ms |
8780 KB |
Output is correct |
8 |
Correct |
16 ms |
8780 KB |
Output is correct |
9 |
Correct |
16 ms |
8780 KB |
Output is correct |
10 |
Correct |
19 ms |
8780 KB |
Output is correct |
11 |
Correct |
16 ms |
8812 KB |
Output is correct |
12 |
Correct |
15 ms |
8712 KB |
Output is correct |
13 |
Correct |
17 ms |
8752 KB |
Output is correct |
14 |
Correct |
20 ms |
8820 KB |
Output is correct |
15 |
Correct |
16 ms |
8788 KB |
Output is correct |
16 |
Correct |
17 ms |
8908 KB |
Output is correct |
17 |
Correct |
17 ms |
8780 KB |
Output is correct |
18 |
Correct |
17 ms |
8808 KB |
Output is correct |
19 |
Correct |
760 ms |
21824 KB |
Output is correct |
20 |
Correct |
717 ms |
21928 KB |
Output is correct |
21 |
Correct |
825 ms |
21824 KB |
Output is correct |
22 |
Correct |
874 ms |
21980 KB |
Output is correct |
23 |
Correct |
869 ms |
22072 KB |
Output is correct |
24 |
Correct |
834 ms |
22224 KB |
Output is correct |
25 |
Correct |
858 ms |
22052 KB |
Output is correct |
26 |
Correct |
884 ms |
22108 KB |
Output is correct |
27 |
Correct |
851 ms |
21984 KB |
Output is correct |
28 |
Correct |
854 ms |
21924 KB |
Output is correct |
29 |
Correct |
879 ms |
21988 KB |
Output is correct |
30 |
Correct |
806 ms |
22024 KB |
Output is correct |
31 |
Correct |
1114 ms |
22080 KB |
Output is correct |
32 |
Correct |
1202 ms |
22044 KB |
Output is correct |
33 |
Correct |
1167 ms |
21960 KB |
Output is correct |
34 |
Correct |
1037 ms |
21964 KB |
Output is correct |
35 |
Correct |
1073 ms |
22088 KB |
Output is correct |
36 |
Correct |
1136 ms |
21928 KB |
Output is correct |
37 |
Correct |
1137 ms |
21992 KB |
Output is correct |
38 |
Correct |
1142 ms |
21992 KB |
Output is correct |
39 |
Correct |
1070 ms |
21972 KB |
Output is correct |
40 |
Correct |
1006 ms |
21976 KB |
Output is correct |
41 |
Correct |
596 ms |
19004 KB |
Output is correct |
42 |
Correct |
118 ms |
10692 KB |
Output is correct |
43 |
Correct |
612 ms |
18864 KB |
Output is correct |
44 |
Correct |
469 ms |
15788 KB |
Output is correct |
45 |
Correct |
64 ms |
9712 KB |
Output is correct |
46 |
Correct |
20 ms |
8860 KB |
Output is correct |
47 |
Correct |
295 ms |
13540 KB |
Output is correct |
48 |
Correct |
207 ms |
12028 KB |
Output is correct |
49 |
Correct |
48 ms |
9384 KB |
Output is correct |
50 |
Correct |
18 ms |
8888 KB |
Output is correct |
51 |
Correct |
179 ms |
11648 KB |
Output is correct |
52 |
Correct |
506 ms |
17200 KB |
Output is correct |
53 |
Correct |
415 ms |
15940 KB |
Output is correct |
54 |
Correct |
396 ms |
15036 KB |
Output is correct |
55 |
Correct |
87 ms |
10164 KB |
Output is correct |
56 |
Correct |
381 ms |
13912 KB |
Output is correct |
57 |
Correct |
157 ms |
11076 KB |
Output is correct |
58 |
Correct |
131 ms |
10688 KB |
Output is correct |
59 |
Correct |
39 ms |
9212 KB |
Output is correct |
60 |
Correct |
639 ms |
16364 KB |
Output is correct |
61 |
Correct |
13 ms |
8800 KB |
Output is correct |
62 |
Correct |
256 ms |
12380 KB |
Output is correct |
63 |
Correct |
127 ms |
10716 KB |
Output is correct |
64 |
Correct |
392 ms |
14220 KB |
Output is correct |
65 |
Correct |
338 ms |
13596 KB |
Output is correct |
66 |
Correct |
87 ms |
10060 KB |
Output is correct |
67 |
Correct |
267 ms |
12592 KB |
Output is correct |
68 |
Correct |
165 ms |
11204 KB |
Output is correct |
69 |
Correct |
312 ms |
13464 KB |
Output is correct |
70 |
Correct |
75 ms |
9728 KB |
Output is correct |
71 |
Execution timed out |
4075 ms |
71848 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |