#include<bits/stdc++.h>
using namespace std;
const int maxn=300000+10;
int all[maxn],n,d,kaf=(1<<19);
vector<pair<int,int>>v;
bool cmp(pair<int,int>a,pair<int,int>b){
if(a.first==b.first){
return a.second>b.second;
}
return a.first<b.first;
}
struct segmenta{
long long seg[(1<<20)];
segmenta(){
for(int i=0;i<(1<<20);i++){
seg[i]=1;
}
}
void upd(int i,int l,int r,int tl,int tr){
if(l>r||l>tr||r<tl||tl>tr||seg[i]==0){
return ;
}
if(l>=tl&&r<=tr){
seg[i]=0;
return ;
}
int m=(l+r)>>1;
upd((i<<1),l,m,tl,tr);
upd((i<<1)^1,m+1,r,tl,tr);
seg[i]=seg[(i<<1)]|seg[(i<<1)^1];
return ;
}
int pors(int i,int l,int r,int tl,int tr){
if(l>r||l>tr||r<tl||tl>tr||seg[i]==0){
return 0;
}
if(l==r){
return l;
}
int m=(l+r)>>1;
int ret=pors((i<<1)^1,m+1,r,tl,tr);
if(ret==0){
return pors((i<<1),l,m,tl,tr);
}
return ret;
}
}seg1;
struct segment{
long long seg[(1<<20)];
void ins(int i,long long w){
while(i>0){
seg[i]=max(seg[i],w);
i>>=1;
}
}
int pors(int i,int l,int r,int tl,int tr){
if(l>r||l>tr||r<tl||tl>tr){
return 0;
}
if(l>=tl&&r<=tr){
return seg[i];
}
int m=(l+r)>>1;
return max(pors((i<<1),l,m,tl,tr),pors((i<<1)^1,m+1,r,tl,tr));
}
}seg;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>d;
for(int i=1;i<=n;i++){
cin>>all[i];
v.push_back(make_pair(all[i],i));
}
sort(v.begin(),v.end(),cmp);
for(int i=0;i<n;i++){
int ind=v[i].second;
seg1.upd(1,0,kaf-1,ind-d+1,ind);
int l=seg1.pors(1,0,kaf-1,0,ind-1);
int res=seg.pors(1,0,kaf-1,l,ind-1)+1;
seg.ins(ind+kaf,res);
}
// for(int i=1;i<=n;i++){
// cout<<i<<" "<<seg.pors(1,0,kaf-1,i,i)<<endl;
// }
cout<<seg.pors(1,0,kaf-1,1,n)<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10584 KB |
Output is correct |
3 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
10584 KB |
Output is correct |
6 |
Correct |
2 ms |
10692 KB |
Output is correct |
7 |
Correct |
3 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10588 KB |
Output is correct |
12 |
Correct |
3 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
3 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
2 ms |
10680 KB |
Output is correct |
17 |
Correct |
4 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
3 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10584 KB |
Output is correct |
23 |
Correct |
3 ms |
10584 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
3 ms |
10588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10584 KB |
Output is correct |
3 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
10584 KB |
Output is correct |
6 |
Correct |
2 ms |
10692 KB |
Output is correct |
7 |
Correct |
3 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10588 KB |
Output is correct |
12 |
Correct |
3 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
3 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
2 ms |
10680 KB |
Output is correct |
17 |
Correct |
4 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
3 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10584 KB |
Output is correct |
23 |
Correct |
3 ms |
10584 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
3 ms |
10588 KB |
Output is correct |
27 |
Correct |
3 ms |
10588 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
3 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
2 ms |
10740 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10588 KB |
Output is correct |
37 |
Correct |
3 ms |
10592 KB |
Output is correct |
38 |
Correct |
2 ms |
10588 KB |
Output is correct |
39 |
Correct |
2 ms |
10692 KB |
Output is correct |
40 |
Correct |
2 ms |
10588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10584 KB |
Output is correct |
3 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
10584 KB |
Output is correct |
6 |
Correct |
2 ms |
10692 KB |
Output is correct |
7 |
Correct |
3 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10588 KB |
Output is correct |
12 |
Correct |
3 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
3 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
2 ms |
10680 KB |
Output is correct |
17 |
Correct |
4 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
3 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10584 KB |
Output is correct |
23 |
Correct |
3 ms |
10584 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
3 ms |
10588 KB |
Output is correct |
27 |
Correct |
3 ms |
10588 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
3 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
2 ms |
10740 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10588 KB |
Output is correct |
37 |
Correct |
3 ms |
10592 KB |
Output is correct |
38 |
Correct |
2 ms |
10588 KB |
Output is correct |
39 |
Correct |
2 ms |
10692 KB |
Output is correct |
40 |
Correct |
2 ms |
10588 KB |
Output is correct |
41 |
Correct |
7 ms |
10992 KB |
Output is correct |
42 |
Correct |
6 ms |
10844 KB |
Output is correct |
43 |
Correct |
6 ms |
10848 KB |
Output is correct |
44 |
Correct |
5 ms |
10844 KB |
Output is correct |
45 |
Correct |
5 ms |
10844 KB |
Output is correct |
46 |
Correct |
5 ms |
10840 KB |
Output is correct |
47 |
Correct |
8 ms |
10844 KB |
Output is correct |
48 |
Correct |
6 ms |
10844 KB |
Output is correct |
49 |
Correct |
5 ms |
10840 KB |
Output is correct |
50 |
Correct |
5 ms |
10844 KB |
Output is correct |
51 |
Correct |
6 ms |
10996 KB |
Output is correct |
52 |
Correct |
6 ms |
11100 KB |
Output is correct |
53 |
Correct |
5 ms |
10844 KB |
Output is correct |
54 |
Correct |
5 ms |
10844 KB |
Output is correct |
55 |
Correct |
5 ms |
10844 KB |
Output is correct |
56 |
Correct |
5 ms |
10844 KB |
Output is correct |
57 |
Correct |
5 ms |
10840 KB |
Output is correct |
58 |
Correct |
4 ms |
10840 KB |
Output is correct |
59 |
Correct |
4 ms |
10844 KB |
Output is correct |
60 |
Correct |
5 ms |
10844 KB |
Output is correct |
61 |
Correct |
7 ms |
10840 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
18620 KB |
Output is correct |
2 |
Correct |
164 ms |
19644 KB |
Output is correct |
3 |
Correct |
224 ms |
19852 KB |
Output is correct |
4 |
Correct |
214 ms |
19600 KB |
Output is correct |
5 |
Correct |
184 ms |
19788 KB |
Output is correct |
6 |
Correct |
222 ms |
18876 KB |
Output is correct |
7 |
Correct |
155 ms |
20312 KB |
Output is correct |
8 |
Correct |
129 ms |
22144 KB |
Output is correct |
9 |
Correct |
160 ms |
23492 KB |
Output is correct |
10 |
Correct |
154 ms |
22208 KB |
Output is correct |
11 |
Correct |
187 ms |
21868 KB |
Output is correct |
12 |
Correct |
214 ms |
23304 KB |
Output is correct |
13 |
Correct |
207 ms |
21740 KB |
Output is correct |
14 |
Correct |
204 ms |
21700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
75 ms |
18652 KB |
Output is correct |
2 |
Correct |
111 ms |
19488 KB |
Output is correct |
3 |
Correct |
117 ms |
19392 KB |
Output is correct |
4 |
Correct |
113 ms |
19464 KB |
Output is correct |
5 |
Correct |
109 ms |
18636 KB |
Output is correct |
6 |
Correct |
116 ms |
18876 KB |
Output is correct |
7 |
Correct |
119 ms |
18644 KB |
Output is correct |
8 |
Correct |
75 ms |
20020 KB |
Output is correct |
9 |
Correct |
122 ms |
20124 KB |
Output is correct |
10 |
Correct |
105 ms |
18624 KB |
Output is correct |
11 |
Correct |
119 ms |
18880 KB |
Output is correct |
12 |
Correct |
104 ms |
19132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10584 KB |
Output is correct |
2 |
Correct |
2 ms |
10584 KB |
Output is correct |
3 |
Correct |
3 ms |
10588 KB |
Output is correct |
4 |
Correct |
2 ms |
10588 KB |
Output is correct |
5 |
Correct |
3 ms |
10584 KB |
Output is correct |
6 |
Correct |
2 ms |
10692 KB |
Output is correct |
7 |
Correct |
3 ms |
10584 KB |
Output is correct |
8 |
Correct |
2 ms |
10588 KB |
Output is correct |
9 |
Correct |
3 ms |
10588 KB |
Output is correct |
10 |
Correct |
2 ms |
10588 KB |
Output is correct |
11 |
Correct |
2 ms |
10588 KB |
Output is correct |
12 |
Correct |
3 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
3 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
10588 KB |
Output is correct |
16 |
Correct |
2 ms |
10680 KB |
Output is correct |
17 |
Correct |
4 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
2 ms |
10588 KB |
Output is correct |
20 |
Correct |
2 ms |
10588 KB |
Output is correct |
21 |
Correct |
3 ms |
10588 KB |
Output is correct |
22 |
Correct |
2 ms |
10584 KB |
Output is correct |
23 |
Correct |
3 ms |
10584 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
3 ms |
10588 KB |
Output is correct |
27 |
Correct |
3 ms |
10588 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
3 ms |
10588 KB |
Output is correct |
30 |
Correct |
2 ms |
10588 KB |
Output is correct |
31 |
Correct |
2 ms |
10740 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
10588 KB |
Output is correct |
34 |
Correct |
2 ms |
10588 KB |
Output is correct |
35 |
Correct |
2 ms |
10588 KB |
Output is correct |
36 |
Correct |
2 ms |
10588 KB |
Output is correct |
37 |
Correct |
3 ms |
10592 KB |
Output is correct |
38 |
Correct |
2 ms |
10588 KB |
Output is correct |
39 |
Correct |
2 ms |
10692 KB |
Output is correct |
40 |
Correct |
2 ms |
10588 KB |
Output is correct |
41 |
Correct |
7 ms |
10992 KB |
Output is correct |
42 |
Correct |
6 ms |
10844 KB |
Output is correct |
43 |
Correct |
6 ms |
10848 KB |
Output is correct |
44 |
Correct |
5 ms |
10844 KB |
Output is correct |
45 |
Correct |
5 ms |
10844 KB |
Output is correct |
46 |
Correct |
5 ms |
10840 KB |
Output is correct |
47 |
Correct |
8 ms |
10844 KB |
Output is correct |
48 |
Correct |
6 ms |
10844 KB |
Output is correct |
49 |
Correct |
5 ms |
10840 KB |
Output is correct |
50 |
Correct |
5 ms |
10844 KB |
Output is correct |
51 |
Correct |
6 ms |
10996 KB |
Output is correct |
52 |
Correct |
6 ms |
11100 KB |
Output is correct |
53 |
Correct |
5 ms |
10844 KB |
Output is correct |
54 |
Correct |
5 ms |
10844 KB |
Output is correct |
55 |
Correct |
5 ms |
10844 KB |
Output is correct |
56 |
Correct |
5 ms |
10844 KB |
Output is correct |
57 |
Correct |
5 ms |
10840 KB |
Output is correct |
58 |
Correct |
4 ms |
10840 KB |
Output is correct |
59 |
Correct |
4 ms |
10844 KB |
Output is correct |
60 |
Correct |
5 ms |
10844 KB |
Output is correct |
61 |
Correct |
7 ms |
10840 KB |
Output is correct |
62 |
Correct |
138 ms |
18620 KB |
Output is correct |
63 |
Correct |
164 ms |
19644 KB |
Output is correct |
64 |
Correct |
224 ms |
19852 KB |
Output is correct |
65 |
Correct |
214 ms |
19600 KB |
Output is correct |
66 |
Correct |
184 ms |
19788 KB |
Output is correct |
67 |
Correct |
222 ms |
18876 KB |
Output is correct |
68 |
Correct |
155 ms |
20312 KB |
Output is correct |
69 |
Correct |
129 ms |
22144 KB |
Output is correct |
70 |
Correct |
160 ms |
23492 KB |
Output is correct |
71 |
Correct |
154 ms |
22208 KB |
Output is correct |
72 |
Correct |
187 ms |
21868 KB |
Output is correct |
73 |
Correct |
214 ms |
23304 KB |
Output is correct |
74 |
Correct |
207 ms |
21740 KB |
Output is correct |
75 |
Correct |
204 ms |
21700 KB |
Output is correct |
76 |
Correct |
75 ms |
18652 KB |
Output is correct |
77 |
Correct |
111 ms |
19488 KB |
Output is correct |
78 |
Correct |
117 ms |
19392 KB |
Output is correct |
79 |
Correct |
113 ms |
19464 KB |
Output is correct |
80 |
Correct |
109 ms |
18636 KB |
Output is correct |
81 |
Correct |
116 ms |
18876 KB |
Output is correct |
82 |
Correct |
119 ms |
18644 KB |
Output is correct |
83 |
Correct |
75 ms |
20020 KB |
Output is correct |
84 |
Correct |
122 ms |
20124 KB |
Output is correct |
85 |
Correct |
105 ms |
18624 KB |
Output is correct |
86 |
Correct |
119 ms |
18880 KB |
Output is correct |
87 |
Correct |
104 ms |
19132 KB |
Output is correct |
88 |
Correct |
237 ms |
22204 KB |
Output is correct |
89 |
Correct |
214 ms |
22696 KB |
Output is correct |
90 |
Correct |
191 ms |
23236 KB |
Output is correct |
91 |
Correct |
128 ms |
21692 KB |
Output is correct |
92 |
Correct |
113 ms |
21484 KB |
Output is correct |
93 |
Correct |
119 ms |
23432 KB |
Output is correct |
94 |
Correct |
138 ms |
22428 KB |
Output is correct |
95 |
Correct |
205 ms |
23324 KB |
Output is correct |
96 |
Correct |
192 ms |
21808 KB |
Output is correct |
97 |
Correct |
154 ms |
22964 KB |
Output is correct |
98 |
Correct |
129 ms |
23232 KB |
Output is correct |
99 |
Correct |
117 ms |
22980 KB |
Output is correct |
100 |
Correct |
114 ms |
21696 KB |
Output is correct |
101 |
Correct |
137 ms |
23248 KB |
Output is correct |
102 |
Correct |
120 ms |
23164 KB |
Output is correct |
103 |
Correct |
113 ms |
21860 KB |
Output is correct |
104 |
Correct |
111 ms |
22216 KB |
Output is correct |
105 |
Correct |
109 ms |
21600 KB |
Output is correct |
106 |
Correct |
145 ms |
21692 KB |
Output is correct |
107 |
Correct |
148 ms |
22120 KB |
Output is correct |
108 |
Correct |
136 ms |
22108 KB |
Output is correct |
109 |
Correct |
195 ms |
22000 KB |
Output is correct |
110 |
Correct |
152 ms |
21792 KB |
Output is correct |
111 |
Correct |
135 ms |
21816 KB |
Output is correct |
112 |
Correct |
117 ms |
22716 KB |
Output is correct |
113 |
Correct |
114 ms |
22116 KB |
Output is correct |
114 |
Correct |
114 ms |
22652 KB |
Output is correct |
115 |
Correct |
77 ms |
22116 KB |
Output is correct |
116 |
Correct |
83 ms |
22792 KB |
Output is correct |
117 |
Correct |
103 ms |
21848 KB |
Output is correct |
118 |
Correct |
105 ms |
21740 KB |
Output is correct |
119 |
Correct |
113 ms |
22464 KB |
Output is correct |
120 |
Correct |
102 ms |
23024 KB |
Output is correct |