# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
336223 |
2020-12-15T03:02:33 Z |
YJU |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
168808 KB |
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e6+5;
const ll K=350;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll u[N],n,m,cnt[N],ans[N],dp[N],s[N];
vector<pll> v[2][N];
ll seg[2][4*N];
void ins(ll sid,ll id,ll l,ll r,ll to,ll d){
if(l==r-1){seg[sid][id]+=d;return ;}
ll mid=(l+r)/2;
if(to<mid){
ins(sid,id*2,l,mid,to,d);
}else{
ins(sid,id*2+1,mid,r,to,d);
}
seg[sid][id]=max(seg[sid][id*2],seg[sid][id*2+1]);
}
void add(ll sid,pll A){
if(A.X==A.Y){
v[sid][A.X].pb(A);
}else{
v[sid][A.X].pb(A);
v[sid][A.Y].pb(A);
}
if(A.X)ins(sid,1,1,m+1,A.X,1);
if(A.Y)ins(sid,1,1,m+1,A.Y,1);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
REP1(i,n){
cin>>u[i];
++cnt[u[i]];
pll tmp=mp(u[i-1],u[i]);
add(i&1,tmp);
if(i==n)add((i+1)&1,mp(u[i],u[i+1]));
}
REP1(i,m){
for(auto j:v[0][i]){
if(j.X)ins(0,1,1,m+1,j.X,-1);
if(j.Y)ins(0,1,1,m+1,j.Y,-1);
}
for(auto j:v[1][i]){
if(j.X)ins(1,1,1,m+1,j.X,-1);
if(j.Y)ins(1,1,1,m+1,j.Y,-1);
}
ans[i]=n-cnt[i]-max(0LL,max(seg[0][1],seg[1][1]));
for(auto j:v[0][i]){
if(j.X)ins(0,1,1,m+1,j.X,1);
if(j.Y)ins(0,1,1,m+1,j.Y,1);
}
for(auto j:v[1][i]){
if(j.X)ins(1,1,1,m+1,j.X,1);
if(j.Y)ins(1,1,1,m+1,j.Y,1);
}
}
REP1(i,m)cout<<ans[i]<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
47340 KB |
Output is correct |
2 |
Correct |
28 ms |
47408 KB |
Output is correct |
3 |
Correct |
28 ms |
47340 KB |
Output is correct |
4 |
Correct |
29 ms |
47340 KB |
Output is correct |
5 |
Correct |
28 ms |
47340 KB |
Output is correct |
6 |
Correct |
28 ms |
47340 KB |
Output is correct |
7 |
Correct |
32 ms |
47340 KB |
Output is correct |
8 |
Correct |
29 ms |
47340 KB |
Output is correct |
9 |
Correct |
29 ms |
47340 KB |
Output is correct |
10 |
Correct |
29 ms |
47340 KB |
Output is correct |
11 |
Correct |
29 ms |
47340 KB |
Output is correct |
12 |
Correct |
28 ms |
47340 KB |
Output is correct |
13 |
Correct |
28 ms |
47340 KB |
Output is correct |
14 |
Correct |
29 ms |
47340 KB |
Output is correct |
15 |
Correct |
30 ms |
47340 KB |
Output is correct |
16 |
Correct |
29 ms |
47340 KB |
Output is correct |
17 |
Correct |
28 ms |
47340 KB |
Output is correct |
18 |
Correct |
30 ms |
47404 KB |
Output is correct |
19 |
Correct |
28 ms |
47340 KB |
Output is correct |
20 |
Correct |
29 ms |
47340 KB |
Output is correct |
21 |
Correct |
28 ms |
47340 KB |
Output is correct |
22 |
Correct |
28 ms |
47468 KB |
Output is correct |
23 |
Correct |
28 ms |
47340 KB |
Output is correct |
24 |
Correct |
28 ms |
47340 KB |
Output is correct |
25 |
Correct |
29 ms |
47340 KB |
Output is correct |
26 |
Correct |
29 ms |
47340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
47340 KB |
Output is correct |
2 |
Correct |
28 ms |
47408 KB |
Output is correct |
3 |
Correct |
28 ms |
47340 KB |
Output is correct |
4 |
Correct |
29 ms |
47340 KB |
Output is correct |
5 |
Correct |
28 ms |
47340 KB |
Output is correct |
6 |
Correct |
28 ms |
47340 KB |
Output is correct |
7 |
Correct |
32 ms |
47340 KB |
Output is correct |
8 |
Correct |
29 ms |
47340 KB |
Output is correct |
9 |
Correct |
29 ms |
47340 KB |
Output is correct |
10 |
Correct |
29 ms |
47340 KB |
Output is correct |
11 |
Correct |
29 ms |
47340 KB |
Output is correct |
12 |
Correct |
28 ms |
47340 KB |
Output is correct |
13 |
Correct |
28 ms |
47340 KB |
Output is correct |
14 |
Correct |
29 ms |
47340 KB |
Output is correct |
15 |
Correct |
30 ms |
47340 KB |
Output is correct |
16 |
Correct |
29 ms |
47340 KB |
Output is correct |
17 |
Correct |
28 ms |
47340 KB |
Output is correct |
18 |
Correct |
30 ms |
47404 KB |
Output is correct |
19 |
Correct |
28 ms |
47340 KB |
Output is correct |
20 |
Correct |
29 ms |
47340 KB |
Output is correct |
21 |
Correct |
28 ms |
47340 KB |
Output is correct |
22 |
Correct |
28 ms |
47468 KB |
Output is correct |
23 |
Correct |
28 ms |
47340 KB |
Output is correct |
24 |
Correct |
28 ms |
47340 KB |
Output is correct |
25 |
Correct |
29 ms |
47340 KB |
Output is correct |
26 |
Correct |
29 ms |
47340 KB |
Output is correct |
27 |
Correct |
75 ms |
51864 KB |
Output is correct |
28 |
Correct |
59 ms |
51268 KB |
Output is correct |
29 |
Correct |
72 ms |
51912 KB |
Output is correct |
30 |
Correct |
63 ms |
51312 KB |
Output is correct |
31 |
Correct |
75 ms |
51968 KB |
Output is correct |
32 |
Correct |
69 ms |
51284 KB |
Output is correct |
33 |
Correct |
78 ms |
51388 KB |
Output is correct |
34 |
Correct |
65 ms |
51520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
47340 KB |
Output is correct |
2 |
Correct |
28 ms |
47408 KB |
Output is correct |
3 |
Correct |
28 ms |
47340 KB |
Output is correct |
4 |
Correct |
29 ms |
47340 KB |
Output is correct |
5 |
Correct |
28 ms |
47340 KB |
Output is correct |
6 |
Correct |
28 ms |
47340 KB |
Output is correct |
7 |
Correct |
32 ms |
47340 KB |
Output is correct |
8 |
Correct |
29 ms |
47340 KB |
Output is correct |
9 |
Correct |
29 ms |
47340 KB |
Output is correct |
10 |
Correct |
29 ms |
47340 KB |
Output is correct |
11 |
Correct |
29 ms |
47340 KB |
Output is correct |
12 |
Correct |
28 ms |
47340 KB |
Output is correct |
13 |
Correct |
28 ms |
47340 KB |
Output is correct |
14 |
Correct |
29 ms |
47340 KB |
Output is correct |
15 |
Correct |
30 ms |
47340 KB |
Output is correct |
16 |
Correct |
29 ms |
47340 KB |
Output is correct |
17 |
Correct |
28 ms |
47340 KB |
Output is correct |
18 |
Correct |
30 ms |
47404 KB |
Output is correct |
19 |
Correct |
28 ms |
47340 KB |
Output is correct |
20 |
Correct |
29 ms |
47340 KB |
Output is correct |
21 |
Correct |
28 ms |
47340 KB |
Output is correct |
22 |
Correct |
28 ms |
47468 KB |
Output is correct |
23 |
Correct |
28 ms |
47340 KB |
Output is correct |
24 |
Correct |
28 ms |
47340 KB |
Output is correct |
25 |
Correct |
29 ms |
47340 KB |
Output is correct |
26 |
Correct |
29 ms |
47340 KB |
Output is correct |
27 |
Correct |
75 ms |
51864 KB |
Output is correct |
28 |
Correct |
59 ms |
51268 KB |
Output is correct |
29 |
Correct |
72 ms |
51912 KB |
Output is correct |
30 |
Correct |
63 ms |
51312 KB |
Output is correct |
31 |
Correct |
75 ms |
51968 KB |
Output is correct |
32 |
Correct |
69 ms |
51284 KB |
Output is correct |
33 |
Correct |
78 ms |
51388 KB |
Output is correct |
34 |
Correct |
65 ms |
51520 KB |
Output is correct |
35 |
Correct |
152 ms |
52588 KB |
Output is correct |
36 |
Correct |
146 ms |
53100 KB |
Output is correct |
37 |
Correct |
139 ms |
52972 KB |
Output is correct |
38 |
Correct |
137 ms |
52844 KB |
Output is correct |
39 |
Correct |
141 ms |
52972 KB |
Output is correct |
40 |
Correct |
135 ms |
53484 KB |
Output is correct |
41 |
Correct |
135 ms |
53356 KB |
Output is correct |
42 |
Correct |
131 ms |
53484 KB |
Output is correct |
43 |
Correct |
129 ms |
53356 KB |
Output is correct |
44 |
Correct |
133 ms |
53356 KB |
Output is correct |
45 |
Correct |
142 ms |
53484 KB |
Output is correct |
46 |
Correct |
130 ms |
53100 KB |
Output is correct |
47 |
Correct |
129 ms |
53612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
47340 KB |
Output is correct |
2 |
Correct |
28 ms |
47408 KB |
Output is correct |
3 |
Correct |
28 ms |
47340 KB |
Output is correct |
4 |
Correct |
29 ms |
47340 KB |
Output is correct |
5 |
Correct |
28 ms |
47340 KB |
Output is correct |
6 |
Correct |
28 ms |
47340 KB |
Output is correct |
7 |
Correct |
32 ms |
47340 KB |
Output is correct |
8 |
Correct |
29 ms |
47340 KB |
Output is correct |
9 |
Correct |
29 ms |
47340 KB |
Output is correct |
10 |
Correct |
29 ms |
47340 KB |
Output is correct |
11 |
Correct |
29 ms |
47340 KB |
Output is correct |
12 |
Correct |
28 ms |
47340 KB |
Output is correct |
13 |
Correct |
28 ms |
47340 KB |
Output is correct |
14 |
Correct |
29 ms |
47340 KB |
Output is correct |
15 |
Correct |
30 ms |
47340 KB |
Output is correct |
16 |
Correct |
29 ms |
47340 KB |
Output is correct |
17 |
Correct |
28 ms |
47340 KB |
Output is correct |
18 |
Correct |
30 ms |
47404 KB |
Output is correct |
19 |
Correct |
28 ms |
47340 KB |
Output is correct |
20 |
Correct |
29 ms |
47340 KB |
Output is correct |
21 |
Correct |
28 ms |
47340 KB |
Output is correct |
22 |
Correct |
28 ms |
47468 KB |
Output is correct |
23 |
Correct |
28 ms |
47340 KB |
Output is correct |
24 |
Correct |
28 ms |
47340 KB |
Output is correct |
25 |
Correct |
29 ms |
47340 KB |
Output is correct |
26 |
Correct |
29 ms |
47340 KB |
Output is correct |
27 |
Correct |
75 ms |
51864 KB |
Output is correct |
28 |
Correct |
59 ms |
51268 KB |
Output is correct |
29 |
Correct |
72 ms |
51912 KB |
Output is correct |
30 |
Correct |
63 ms |
51312 KB |
Output is correct |
31 |
Correct |
75 ms |
51968 KB |
Output is correct |
32 |
Correct |
69 ms |
51284 KB |
Output is correct |
33 |
Correct |
78 ms |
51388 KB |
Output is correct |
34 |
Correct |
65 ms |
51520 KB |
Output is correct |
35 |
Correct |
152 ms |
52588 KB |
Output is correct |
36 |
Correct |
146 ms |
53100 KB |
Output is correct |
37 |
Correct |
139 ms |
52972 KB |
Output is correct |
38 |
Correct |
137 ms |
52844 KB |
Output is correct |
39 |
Correct |
141 ms |
52972 KB |
Output is correct |
40 |
Correct |
135 ms |
53484 KB |
Output is correct |
41 |
Correct |
135 ms |
53356 KB |
Output is correct |
42 |
Correct |
131 ms |
53484 KB |
Output is correct |
43 |
Correct |
129 ms |
53356 KB |
Output is correct |
44 |
Correct |
133 ms |
53356 KB |
Output is correct |
45 |
Correct |
142 ms |
53484 KB |
Output is correct |
46 |
Correct |
130 ms |
53100 KB |
Output is correct |
47 |
Correct |
129 ms |
53612 KB |
Output is correct |
48 |
Correct |
1569 ms |
112236 KB |
Output is correct |
49 |
Correct |
1527 ms |
112620 KB |
Output is correct |
50 |
Correct |
1561 ms |
112236 KB |
Output is correct |
51 |
Correct |
1335 ms |
109164 KB |
Output is correct |
52 |
Correct |
1253 ms |
99820 KB |
Output is correct |
53 |
Correct |
1415 ms |
105196 KB |
Output is correct |
54 |
Correct |
1395 ms |
98024 KB |
Output is correct |
55 |
Correct |
1392 ms |
96748 KB |
Output is correct |
56 |
Correct |
1404 ms |
94444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
47340 KB |
Output is correct |
2 |
Correct |
28 ms |
47408 KB |
Output is correct |
3 |
Correct |
28 ms |
47340 KB |
Output is correct |
4 |
Correct |
29 ms |
47340 KB |
Output is correct |
5 |
Correct |
28 ms |
47340 KB |
Output is correct |
6 |
Correct |
28 ms |
47340 KB |
Output is correct |
7 |
Correct |
32 ms |
47340 KB |
Output is correct |
8 |
Correct |
29 ms |
47340 KB |
Output is correct |
9 |
Correct |
29 ms |
47340 KB |
Output is correct |
10 |
Correct |
29 ms |
47340 KB |
Output is correct |
11 |
Correct |
29 ms |
47340 KB |
Output is correct |
12 |
Correct |
28 ms |
47340 KB |
Output is correct |
13 |
Correct |
28 ms |
47340 KB |
Output is correct |
14 |
Correct |
29 ms |
47340 KB |
Output is correct |
15 |
Correct |
30 ms |
47340 KB |
Output is correct |
16 |
Correct |
29 ms |
47340 KB |
Output is correct |
17 |
Correct |
28 ms |
47340 KB |
Output is correct |
18 |
Correct |
30 ms |
47404 KB |
Output is correct |
19 |
Correct |
28 ms |
47340 KB |
Output is correct |
20 |
Correct |
29 ms |
47340 KB |
Output is correct |
21 |
Correct |
28 ms |
47340 KB |
Output is correct |
22 |
Correct |
28 ms |
47468 KB |
Output is correct |
23 |
Correct |
28 ms |
47340 KB |
Output is correct |
24 |
Correct |
28 ms |
47340 KB |
Output is correct |
25 |
Correct |
29 ms |
47340 KB |
Output is correct |
26 |
Correct |
29 ms |
47340 KB |
Output is correct |
27 |
Correct |
75 ms |
51864 KB |
Output is correct |
28 |
Correct |
59 ms |
51268 KB |
Output is correct |
29 |
Correct |
72 ms |
51912 KB |
Output is correct |
30 |
Correct |
63 ms |
51312 KB |
Output is correct |
31 |
Correct |
75 ms |
51968 KB |
Output is correct |
32 |
Correct |
69 ms |
51284 KB |
Output is correct |
33 |
Correct |
78 ms |
51388 KB |
Output is correct |
34 |
Correct |
65 ms |
51520 KB |
Output is correct |
35 |
Correct |
152 ms |
52588 KB |
Output is correct |
36 |
Correct |
146 ms |
53100 KB |
Output is correct |
37 |
Correct |
139 ms |
52972 KB |
Output is correct |
38 |
Correct |
137 ms |
52844 KB |
Output is correct |
39 |
Correct |
141 ms |
52972 KB |
Output is correct |
40 |
Correct |
135 ms |
53484 KB |
Output is correct |
41 |
Correct |
135 ms |
53356 KB |
Output is correct |
42 |
Correct |
131 ms |
53484 KB |
Output is correct |
43 |
Correct |
129 ms |
53356 KB |
Output is correct |
44 |
Correct |
133 ms |
53356 KB |
Output is correct |
45 |
Correct |
142 ms |
53484 KB |
Output is correct |
46 |
Correct |
130 ms |
53100 KB |
Output is correct |
47 |
Correct |
129 ms |
53612 KB |
Output is correct |
48 |
Correct |
1569 ms |
112236 KB |
Output is correct |
49 |
Correct |
1527 ms |
112620 KB |
Output is correct |
50 |
Correct |
1561 ms |
112236 KB |
Output is correct |
51 |
Correct |
1335 ms |
109164 KB |
Output is correct |
52 |
Correct |
1253 ms |
99820 KB |
Output is correct |
53 |
Correct |
1415 ms |
105196 KB |
Output is correct |
54 |
Correct |
1395 ms |
98024 KB |
Output is correct |
55 |
Correct |
1392 ms |
96748 KB |
Output is correct |
56 |
Correct |
1404 ms |
94444 KB |
Output is correct |
57 |
Execution timed out |
2585 ms |
168808 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |