# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
336237 |
2020-12-15T03:19:33 Z |
YJU |
Rope (JOI17_rope) |
C++14 |
|
2500 ms |
83456 KB |
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef int 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];
vector<pair<ll,pll> > v[N];
ll seg[4*N][2];
void ins(ll sid,ll id,ll l,ll r,ll to,ll d){
if(l==r-1){seg[id][sid]+=d;return ;}
ll mid=(l+r)>>1;
if(to<mid){
ins(sid,(id<<1),l,mid,to,d);
}else{
ins(sid,(id<<1)+1,mid,r,to,d);
}
seg[id][sid]=max(seg[id*2][sid],seg[id*2+1][sid]);
}
void add(ll sid,pll A){
if(A.X==A.Y){
if(A.X)v[A.X].pb(mp(sid,A));
}else{
if(A.X)v[A.X].pb(mp(sid,A));
if(A.Y)v[A.Y].pb(mp(sid,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[i]){
if(j.Y.X)ins(j.X,1,1,m+1,j.Y.X,-1);
if(j.Y.Y)ins(j.X,1,1,m+1,j.Y.Y,-1);
}
cout<<n-cnt[i]-max(0,max(seg[1][0],seg[1][1]))<<"\n";
for(auto j:v[i]){
if(j.Y.X)ins(j.X,1,1,m+1,j.Y.X,1);
if(j.Y.Y)ins(j.X,1,1,m+1,j.Y.Y,1);
}
}
return 0;
}
Compilation message
rope.cpp:12:18: warning: overflow in conversion from 'long long int' to 'll' {aka 'int'} changes value from '1152921504606846976' to '0' [-Woverflow]
12 | const ll INF=(1LL<<60);
| ~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
19 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
15 ms |
23788 KB |
Output is correct |
7 |
Correct |
14 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23788 KB |
Output is correct |
9 |
Correct |
14 ms |
23788 KB |
Output is correct |
10 |
Correct |
15 ms |
23788 KB |
Output is correct |
11 |
Correct |
14 ms |
23788 KB |
Output is correct |
12 |
Correct |
14 ms |
23788 KB |
Output is correct |
13 |
Correct |
14 ms |
23788 KB |
Output is correct |
14 |
Correct |
15 ms |
23788 KB |
Output is correct |
15 |
Correct |
16 ms |
23788 KB |
Output is correct |
16 |
Correct |
15 ms |
23916 KB |
Output is correct |
17 |
Correct |
15 ms |
23788 KB |
Output is correct |
18 |
Correct |
15 ms |
23788 KB |
Output is correct |
19 |
Correct |
15 ms |
23788 KB |
Output is correct |
20 |
Correct |
15 ms |
23916 KB |
Output is correct |
21 |
Correct |
15 ms |
23788 KB |
Output is correct |
22 |
Correct |
15 ms |
23788 KB |
Output is correct |
23 |
Correct |
15 ms |
23788 KB |
Output is correct |
24 |
Correct |
18 ms |
23788 KB |
Output is correct |
25 |
Correct |
18 ms |
23808 KB |
Output is correct |
26 |
Correct |
17 ms |
23788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
19 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
15 ms |
23788 KB |
Output is correct |
7 |
Correct |
14 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23788 KB |
Output is correct |
9 |
Correct |
14 ms |
23788 KB |
Output is correct |
10 |
Correct |
15 ms |
23788 KB |
Output is correct |
11 |
Correct |
14 ms |
23788 KB |
Output is correct |
12 |
Correct |
14 ms |
23788 KB |
Output is correct |
13 |
Correct |
14 ms |
23788 KB |
Output is correct |
14 |
Correct |
15 ms |
23788 KB |
Output is correct |
15 |
Correct |
16 ms |
23788 KB |
Output is correct |
16 |
Correct |
15 ms |
23916 KB |
Output is correct |
17 |
Correct |
15 ms |
23788 KB |
Output is correct |
18 |
Correct |
15 ms |
23788 KB |
Output is correct |
19 |
Correct |
15 ms |
23788 KB |
Output is correct |
20 |
Correct |
15 ms |
23916 KB |
Output is correct |
21 |
Correct |
15 ms |
23788 KB |
Output is correct |
22 |
Correct |
15 ms |
23788 KB |
Output is correct |
23 |
Correct |
15 ms |
23788 KB |
Output is correct |
24 |
Correct |
18 ms |
23788 KB |
Output is correct |
25 |
Correct |
18 ms |
23808 KB |
Output is correct |
26 |
Correct |
17 ms |
23788 KB |
Output is correct |
27 |
Correct |
55 ms |
26812 KB |
Output is correct |
28 |
Correct |
42 ms |
26392 KB |
Output is correct |
29 |
Correct |
53 ms |
26852 KB |
Output is correct |
30 |
Correct |
46 ms |
26712 KB |
Output is correct |
31 |
Correct |
55 ms |
26908 KB |
Output is correct |
32 |
Correct |
42 ms |
26440 KB |
Output is correct |
33 |
Correct |
54 ms |
26808 KB |
Output is correct |
34 |
Correct |
45 ms |
26712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
19 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
15 ms |
23788 KB |
Output is correct |
7 |
Correct |
14 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23788 KB |
Output is correct |
9 |
Correct |
14 ms |
23788 KB |
Output is correct |
10 |
Correct |
15 ms |
23788 KB |
Output is correct |
11 |
Correct |
14 ms |
23788 KB |
Output is correct |
12 |
Correct |
14 ms |
23788 KB |
Output is correct |
13 |
Correct |
14 ms |
23788 KB |
Output is correct |
14 |
Correct |
15 ms |
23788 KB |
Output is correct |
15 |
Correct |
16 ms |
23788 KB |
Output is correct |
16 |
Correct |
15 ms |
23916 KB |
Output is correct |
17 |
Correct |
15 ms |
23788 KB |
Output is correct |
18 |
Correct |
15 ms |
23788 KB |
Output is correct |
19 |
Correct |
15 ms |
23788 KB |
Output is correct |
20 |
Correct |
15 ms |
23916 KB |
Output is correct |
21 |
Correct |
15 ms |
23788 KB |
Output is correct |
22 |
Correct |
15 ms |
23788 KB |
Output is correct |
23 |
Correct |
15 ms |
23788 KB |
Output is correct |
24 |
Correct |
18 ms |
23788 KB |
Output is correct |
25 |
Correct |
18 ms |
23808 KB |
Output is correct |
26 |
Correct |
17 ms |
23788 KB |
Output is correct |
27 |
Correct |
55 ms |
26812 KB |
Output is correct |
28 |
Correct |
42 ms |
26392 KB |
Output is correct |
29 |
Correct |
53 ms |
26852 KB |
Output is correct |
30 |
Correct |
46 ms |
26712 KB |
Output is correct |
31 |
Correct |
55 ms |
26908 KB |
Output is correct |
32 |
Correct |
42 ms |
26440 KB |
Output is correct |
33 |
Correct |
54 ms |
26808 KB |
Output is correct |
34 |
Correct |
45 ms |
26712 KB |
Output is correct |
35 |
Correct |
112 ms |
27628 KB |
Output is correct |
36 |
Correct |
110 ms |
27688 KB |
Output is correct |
37 |
Correct |
111 ms |
27500 KB |
Output is correct |
38 |
Correct |
112 ms |
27500 KB |
Output is correct |
39 |
Correct |
118 ms |
27628 KB |
Output is correct |
40 |
Correct |
104 ms |
27884 KB |
Output is correct |
41 |
Correct |
103 ms |
27628 KB |
Output is correct |
42 |
Correct |
102 ms |
27756 KB |
Output is correct |
43 |
Correct |
97 ms |
27884 KB |
Output is correct |
44 |
Correct |
104 ms |
27628 KB |
Output is correct |
45 |
Correct |
108 ms |
27908 KB |
Output is correct |
46 |
Correct |
106 ms |
27628 KB |
Output is correct |
47 |
Correct |
99 ms |
28012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
19 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
15 ms |
23788 KB |
Output is correct |
7 |
Correct |
14 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23788 KB |
Output is correct |
9 |
Correct |
14 ms |
23788 KB |
Output is correct |
10 |
Correct |
15 ms |
23788 KB |
Output is correct |
11 |
Correct |
14 ms |
23788 KB |
Output is correct |
12 |
Correct |
14 ms |
23788 KB |
Output is correct |
13 |
Correct |
14 ms |
23788 KB |
Output is correct |
14 |
Correct |
15 ms |
23788 KB |
Output is correct |
15 |
Correct |
16 ms |
23788 KB |
Output is correct |
16 |
Correct |
15 ms |
23916 KB |
Output is correct |
17 |
Correct |
15 ms |
23788 KB |
Output is correct |
18 |
Correct |
15 ms |
23788 KB |
Output is correct |
19 |
Correct |
15 ms |
23788 KB |
Output is correct |
20 |
Correct |
15 ms |
23916 KB |
Output is correct |
21 |
Correct |
15 ms |
23788 KB |
Output is correct |
22 |
Correct |
15 ms |
23788 KB |
Output is correct |
23 |
Correct |
15 ms |
23788 KB |
Output is correct |
24 |
Correct |
18 ms |
23788 KB |
Output is correct |
25 |
Correct |
18 ms |
23808 KB |
Output is correct |
26 |
Correct |
17 ms |
23788 KB |
Output is correct |
27 |
Correct |
55 ms |
26812 KB |
Output is correct |
28 |
Correct |
42 ms |
26392 KB |
Output is correct |
29 |
Correct |
53 ms |
26852 KB |
Output is correct |
30 |
Correct |
46 ms |
26712 KB |
Output is correct |
31 |
Correct |
55 ms |
26908 KB |
Output is correct |
32 |
Correct |
42 ms |
26440 KB |
Output is correct |
33 |
Correct |
54 ms |
26808 KB |
Output is correct |
34 |
Correct |
45 ms |
26712 KB |
Output is correct |
35 |
Correct |
112 ms |
27628 KB |
Output is correct |
36 |
Correct |
110 ms |
27688 KB |
Output is correct |
37 |
Correct |
111 ms |
27500 KB |
Output is correct |
38 |
Correct |
112 ms |
27500 KB |
Output is correct |
39 |
Correct |
118 ms |
27628 KB |
Output is correct |
40 |
Correct |
104 ms |
27884 KB |
Output is correct |
41 |
Correct |
103 ms |
27628 KB |
Output is correct |
42 |
Correct |
102 ms |
27756 KB |
Output is correct |
43 |
Correct |
97 ms |
27884 KB |
Output is correct |
44 |
Correct |
104 ms |
27628 KB |
Output is correct |
45 |
Correct |
108 ms |
27908 KB |
Output is correct |
46 |
Correct |
106 ms |
27628 KB |
Output is correct |
47 |
Correct |
99 ms |
28012 KB |
Output is correct |
48 |
Correct |
1329 ms |
67124 KB |
Output is correct |
49 |
Correct |
1326 ms |
66892 KB |
Output is correct |
50 |
Correct |
1318 ms |
66788 KB |
Output is correct |
51 |
Correct |
1175 ms |
63724 KB |
Output is correct |
52 |
Correct |
1091 ms |
58604 KB |
Output is correct |
53 |
Correct |
1224 ms |
61548 KB |
Output is correct |
54 |
Correct |
1187 ms |
56300 KB |
Output is correct |
55 |
Correct |
1193 ms |
55516 KB |
Output is correct |
56 |
Correct |
1198 ms |
53996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23788 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
19 ms |
23788 KB |
Output is correct |
4 |
Correct |
17 ms |
23788 KB |
Output is correct |
5 |
Correct |
17 ms |
23788 KB |
Output is correct |
6 |
Correct |
15 ms |
23788 KB |
Output is correct |
7 |
Correct |
14 ms |
23788 KB |
Output is correct |
8 |
Correct |
14 ms |
23788 KB |
Output is correct |
9 |
Correct |
14 ms |
23788 KB |
Output is correct |
10 |
Correct |
15 ms |
23788 KB |
Output is correct |
11 |
Correct |
14 ms |
23788 KB |
Output is correct |
12 |
Correct |
14 ms |
23788 KB |
Output is correct |
13 |
Correct |
14 ms |
23788 KB |
Output is correct |
14 |
Correct |
15 ms |
23788 KB |
Output is correct |
15 |
Correct |
16 ms |
23788 KB |
Output is correct |
16 |
Correct |
15 ms |
23916 KB |
Output is correct |
17 |
Correct |
15 ms |
23788 KB |
Output is correct |
18 |
Correct |
15 ms |
23788 KB |
Output is correct |
19 |
Correct |
15 ms |
23788 KB |
Output is correct |
20 |
Correct |
15 ms |
23916 KB |
Output is correct |
21 |
Correct |
15 ms |
23788 KB |
Output is correct |
22 |
Correct |
15 ms |
23788 KB |
Output is correct |
23 |
Correct |
15 ms |
23788 KB |
Output is correct |
24 |
Correct |
18 ms |
23788 KB |
Output is correct |
25 |
Correct |
18 ms |
23808 KB |
Output is correct |
26 |
Correct |
17 ms |
23788 KB |
Output is correct |
27 |
Correct |
55 ms |
26812 KB |
Output is correct |
28 |
Correct |
42 ms |
26392 KB |
Output is correct |
29 |
Correct |
53 ms |
26852 KB |
Output is correct |
30 |
Correct |
46 ms |
26712 KB |
Output is correct |
31 |
Correct |
55 ms |
26908 KB |
Output is correct |
32 |
Correct |
42 ms |
26440 KB |
Output is correct |
33 |
Correct |
54 ms |
26808 KB |
Output is correct |
34 |
Correct |
45 ms |
26712 KB |
Output is correct |
35 |
Correct |
112 ms |
27628 KB |
Output is correct |
36 |
Correct |
110 ms |
27688 KB |
Output is correct |
37 |
Correct |
111 ms |
27500 KB |
Output is correct |
38 |
Correct |
112 ms |
27500 KB |
Output is correct |
39 |
Correct |
118 ms |
27628 KB |
Output is correct |
40 |
Correct |
104 ms |
27884 KB |
Output is correct |
41 |
Correct |
103 ms |
27628 KB |
Output is correct |
42 |
Correct |
102 ms |
27756 KB |
Output is correct |
43 |
Correct |
97 ms |
27884 KB |
Output is correct |
44 |
Correct |
104 ms |
27628 KB |
Output is correct |
45 |
Correct |
108 ms |
27908 KB |
Output is correct |
46 |
Correct |
106 ms |
27628 KB |
Output is correct |
47 |
Correct |
99 ms |
28012 KB |
Output is correct |
48 |
Correct |
1329 ms |
67124 KB |
Output is correct |
49 |
Correct |
1326 ms |
66892 KB |
Output is correct |
50 |
Correct |
1318 ms |
66788 KB |
Output is correct |
51 |
Correct |
1175 ms |
63724 KB |
Output is correct |
52 |
Correct |
1091 ms |
58604 KB |
Output is correct |
53 |
Correct |
1224 ms |
61548 KB |
Output is correct |
54 |
Correct |
1187 ms |
56300 KB |
Output is correct |
55 |
Correct |
1193 ms |
55516 KB |
Output is correct |
56 |
Correct |
1198 ms |
53996 KB |
Output is correct |
57 |
Execution timed out |
2573 ms |
83456 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |