10491 | 2024-04-03 13:17:22 | 111 | Branch Cutting | cpp17 | Wrong answer 8/100 | 354ms | 31692 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,Q;
cin>>N>>Q;
vector<int>v(N),n(N),p(N);
for(int i=0;i<N;i++){
cin>>v[i];
n[i]=i==N-1?0:i+1;
p[i]=i==0?N-1:i-1;
}
int s=min_element(v.begin(),v.end())-v.begin();
map<int,int>z;
for(int i=0,j=0;i<N;i++){
if(v[s]<v[n[s]]){
j++;
}
else if(j){
z.emplace((s-j+N)%N,s);
j=0;
}
s=n[s];
}
int ans=0;
for(auto[x,y]:z){
ans+=((y-x+N)%N+1)/2;
}
cout<<ans<<' ';
for(int i=0;i<Q;i++){
int x;
cin>>x>>v[x];
if(!z.empty()){
auto t=z.upper_bound(x);
t=t==z.begin()?prev(z.end()):prev(t);
int s=t->first,e=t->second;
if(x>=s&&x<=e||x>=s&&s>=e||e>=x&&s>=e){
z.erase(t);
ans-=((e-s+N)%N+1)/2;
if(x==s&&x==e){
}
else if(x==s){
s=n[s];
ans+=((e-s+N)%N+1)/2;
z.emplace(s,e);
}
else if(x==e){
e=p[e];
ans+=((e-s+N)%N+1)/2;
z.emplace(s,e);
}
else{
ans+=((p[x]-s+N)%N+1)/2;
z.emplace(s,p[x]);
ans+=((e-n[x]+N)%N+1)/2;
z.emplace(n[x],e);
}
}
}
int s=v[p[x]]<v[x]?p[x]:x;
int e=v[x]<v[n[x]]?n[x]:x;
if(z.empty()){
ans+=((e-s+N)%N+1)/2;
z.emplace(s,e);
}
else{
auto t=z.upper_bound(x);
if(t==z.end()){
t=z.begin();
}
if(t->first==e){
auto[ss,ee]=*t;
t=z.erase(t);
ans-=((ee-ss+N)%N+1)/2;
e=ee;
}
if(!z.empty()){
t=t==z.begin()?prev(z.end()):prev(t);
if(t->second==s){
auto[ss,ee]=*t;
t=z.erase(t);
ans-=((ee-ss+N)%N+1)/2;
s=ss;
}
}
ans+=((e-s+N)%N+1)/2;
z.emplace(s,e);
}
cout<<ans<<' ';
}
cout<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 2104 KiB | ||||
2 | Accepted | 3ms | 2216 KiB | ||||
subtask2 | 8/8 | ||||||
3 | Accepted | 3ms | 2392 KiB | ||||
4 | Accepted | 3ms | 2504 KiB | ||||
5 | Accepted | 3ms | 2572 KiB | ||||
6 | Accepted | 3ms | 2796 KiB | ||||
7 | Accepted | 3ms | 2836 KiB | ||||
8 | Accepted | 3ms | 2872 KiB | ||||
9 | Accepted | 3ms | 2968 KiB | ||||
10 | Accepted | 3ms | 3100 KiB | ||||
11 | Accepted | 3ms | 3316 KiB | ||||
subtask3 | 0/15 | ||||||
12 | Wrong answer | 335ms | 28844 KiB | ||||
13 | Wrong answer | 314ms | 28452 KiB | ||||
14 | Wrong answer | 307ms | 28168 KiB | ||||
15 | Wrong answer | 331ms | 28864 KiB | ||||
16 | Wrong answer | 354ms | 31692 KiB | ||||
17 | Wrong answer | 280ms | 28520 KiB | ||||
18 | Wrong answer | 279ms | 28372 KiB | ||||
subtask4 | 0/10 | ||||||
19 | Accepted | 3ms | 3656 KiB | ||||
20 | Accepted | 3ms | 3612 KiB | ||||
21 | Accepted | 4ms | 3632 KiB | ||||
22 | Accepted | 4ms | 3632 KiB | ||||
23 | Wrong answer | 4ms | 3636 KiB | ||||
24 | Accepted | 3ms | 3668 KiB | ||||
25 | Accepted | 4ms | 3928 KiB | ||||
26 | Accepted | 4ms | 3976 KiB | ||||
subtask5 | 0/25 | ||||||
27 | Accepted | 4ms | 4376 KiB | ||||
28 | Accepted | 3ms | 4396 KiB | ||||
29 | Wrong answer | 13ms | 4880 KiB | ||||
30 | Wrong answer | 13ms | 4964 KiB | ||||
31 | Wrong answer | 13ms | 4548 KiB | ||||
32 | Accepted | 10ms | 4440 KiB | ||||
33 | Accepted | 10ms | 4480 KiB | ||||
34 | Accepted | 13ms | 4844 KiB | ||||
subtask6 | 0/42 | ||||||
35 | Accepted | 35ms | 13200 KiB | ||||
36 | Accepted | 20ms | 13196 KiB | ||||
37 | Wrong answer | 352ms | 20156 KiB | ||||
38 | Wrong answer | 321ms | 16976 KiB | ||||
39 | Wrong answer | 344ms | 20300 KiB | ||||
40 | Accepted | 225ms | 13660 KiB | ||||
41 | Accepted | 224ms | 13644 KiB | ||||
42 | Accepted | 224ms | 13636 KiB | ||||
43 | Accepted | 347ms | 24460 KiB |