先上 AC 代码:
点击查看代码
/*
Tips:
你数组开小了吗?
你MLE了吗?
你觉得是贪心,是不是该想想dp?
一个小时没调出来,是不是该考虑换题?
*/
#include<bits/stdc++.h>
using namespace std;
#define map unordered_map
#define forl(i,a,b) for(register long long i=a;i<=b;i++)
#define forr(i,a,b) for(register long long i=a;i>=b;i--)
#define forll(i,a,b,c) for(register long long i=a;i<=b;i+=c)
#define forrr(i,a,b,c) for(register long long i=a;i>=b;i-=c)
#define lc(x) x<<1
#define rc(x) x<<1|1
#define mid ((l+r)>>1)
#define cin(x) scanf("%lld",&x)
#define cout(x) printf("%lld",x)
#define lowbit(x) x&-x
#define pb push_back
#define pf push_front
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
#define QwQ return 0;
#define ll long long
#define lcm(x,y) x/__gcd(x,y)*y
#define Sum(x,y) 1ll*(x+y)*(y-x+1)/2
ll t,sq;
struct node{
ll L,R,sum,fir,firpd,beh,behpd,tag,fugai,len,max1,max0,max1pd,max0pd;
}bl[100010];
ll a[100010],b[100010],n,m;
void upd(ll id)
{
if(bl[id].fugai!=-1)
{
forl(i,bl[id].L,bl[id].R)
a[i]=bl[id].fugai;
bl[id].fir=bl[id].len;
bl[id].beh=bl[id].len;
bl[id].firpd=bl[id].fugai;
bl[id].behpd=bl[id].fugai;
bl[id].sum=bl[id].fugai*bl[id].len;
bl[id].max1=bl[id].fugai*bl[id].len;
bl[id].max0=(bl[id].fugai^1)*bl[id].len;
bl[id].max1pd=1;
bl[id].max0pd=1;
bl[id].fugai=-1;
bl[id].tag=0;
return ;
}
if(bl[id].tag)
forl(i,bl[id].L,bl[id].R)
a[i]^=1;
bl[id].sum=0,bl[id].fir=0,bl[id].firpd=0,bl[id].beh=0,bl[id].behpd=0,bl[id].fugai=-1,bl[id].tag=0;
ll sum=0,Maxn=0;
forl(j,bl[id].L,bl[id].R)
{
if(a[j]==1)
sum++;
else
Maxn=max(Maxn,sum),sum=0;
}
bl[id].max1=max(Maxn,sum);
sum=0,Maxn=0;
forl(j,bl[id].L,bl[id].R)
{
if(a[j]==0)
sum++;
else
Maxn=max(Maxn,sum),sum=0;
}
bl[id].max0=max(Maxn,sum);bl[id].max0pd=1;bl[id].max1pd=1;
ll Sum=0;
forl(j,bl[id].L,bl[id].R)
Sum+=a[j];
forl(j,bl[id].L+1,bl[id].R)
{
if(a[bl[id].L]==a[j])
bl[id].fir++;
else
break;
}
bl[id].fir++;
forr(j,bl[id].R-1,bl[id].L)
{
if(a[bl[id].R]==a[j])
bl[id].beh++;
else
break;
}
bl[id].beh++;
bl[id].sum=Sum;
if(a[bl[id].L])
bl[id].firpd=1;
if(a[bl[id].R])
bl[id].behpd=1;
}
void upd1(ll l,ll r)
{
if(b[l]==b[r])
{
upd(b[l]);
forl(i,l,r)
a[i]=0;
upd(b[l]);
return ;
}
upd(b[l]);
forl(i,l,bl[b[l]].R)
a[i]=0;
upd(b[l]);
upd(b[r]);
forl(i,bl[b[r]].L,r)
a[i]=0;
upd(b[r]);
forl(i,b[l]+1,b[r]-1)
bl[i].fugai=0,bl[i].sum=0,bl[i].fir=bl[i].len,bl[i].beh=bl[i].len,
bl[i].firpd=0,bl[i].behpd=0,bl[i].tag=0,
bl[i].max1=bl[i].fugai*bl[i].len,
bl[i].max0=(bl[i].fugai^1)*bl[i].len,
bl[i].max1pd=1,
bl[i].max0pd=1;
}
void upd2(ll l,ll r)
{
if(b[l]==b[r])
{
upd(b[l]);
forl(i,l,r)
a[i]=1;
upd(b[l]);
return ;
}
upd(b[l]);
forl(i,l,bl[b[l]].R)
a[i]=1;
upd(b[l]);
upd(b[r]);
forl(i,bl[b[r]].L,r)
a[i]=1;
upd(b[r]);
forl(i,b[l]+1,b[r]-1)
bl[i].fugai=1,bl[i].sum=bl[i].len,bl[i].fir=bl[i].len,bl[i].beh=bl[i].len,
bl[i].firpd=1,bl[i].behpd=1,bl[i].tag=0,
bl[i].max1=bl[i].fugai*bl[i].len,
bl[i].max0=(bl[i].fugai^1)*bl[i].len,
bl[i].max1pd=1,
bl[i].max0pd=1;
}
void upd3(ll l,ll r)
{
if(b[l]==b[r])
{
upd(b[l]);
forl(i,l,r)
a[i]^=1;
upd(b[l]);
return ;
}
upd(b[l]);
forl(i,l,bl[b[l]].R)
a[i]^=1;
upd(b[l]);
upd(b[r]);
forl(i,bl[b[r]].L,r)
a[i]^=1;
upd(b[r]);
forl(i,b[l]+1,b[r]-1)
{
if(bl[i].fugai==-1)
bl[i].sum=bl[i].len-bl[i].sum,bl[i].firpd^=1,bl[i].behpd^=1,bl[i].tag^=1,swap(bl[i].max1,bl[i].max0);
else
{
bl[i].fugai^=1;
if(bl[i].fugai==1)
bl[i].sum=bl[i].len,bl[i].fir=bl[i].len,bl[i].beh=bl[i].len,bl[i].firpd=1,bl[i].behpd=1;
else
bl[i].sum=0,bl[i].fir=bl[i].len,bl[i].beh=bl[i].len,bl[i].firpd=0,bl[i].behpd=0;
bl[i].max1=bl[i].fugai*bl[i].len;
bl[i].max0=(bl[i].fugai^1)*bl[i].len;
bl[i].max1pd=1;
bl[i].max0pd=1;
}
}
}
ll query1(ll l,ll r)
{
if(b[l]==b[r])
{
ll Sum=0;
upd(b[l]);
forl(i,l,r)
Sum+=a[i];
return Sum;
}
ll Sum=0;
upd(b[l]);
forl(i,l,bl[b[l]].R)
Sum+=a[i];
upd(b[r]);
forl(i,bl[b[r]].L,r)
Sum+=a[i];
forl(i,b[l]+1,b[r]-1)
Sum+=bl[i].sum;
return Sum;
}
ll query2(ll l,ll r)
{
ll Sum=0,maxn=0;
if(b[l]==b[r])
{
upd(b[l]);
forl(i,l,r)
{
if(a[i])
Sum++;
else
maxn=max(maxn,Sum),Sum=0;
}
return max(maxn,Sum);
}
upd(b[l]);
upd(b[r]);
forl(i,l,bl[b[l]].R)
{
if(a[i])
Sum++;
else
maxn=max(maxn,Sum),Sum=0;
}
forl(i,b[l]+1,b[r]-1)
{
if(bl[i].fir*bl[i].firpd==bl[i].len)
{
Sum+=bl[i].len;
continue;
}
/* else if(bl[i].fir==bl[i].len)
{
maxn=max(maxn,Sum);
Sum=0;
continue;
}*/
else
{
Sum+=bl[i].fir*bl[i].firpd;
maxn=max(maxn,Sum);
Sum=bl[i].beh*bl[i].behpd;
}
// if(bl[i].firpd+bl[i].behpd==0)
maxn=max(maxn,bl[i].max1);
}
forl(i,bl[b[r]].L,r)
{
if(a[i]==1)
Sum++;
else
maxn=max(maxn,Sum),Sum=0;
}
return max(maxn,Sum);
}
void solve()
{
cin>>n>>m;
sq=pow(sqrt(n),0.66);
forl(i,1,n)
cin>>a[i];
forl(i,1,n)
{
bl[i].L=bl[i-1].R+1;
bl[i].R=min(n,i*sq);
ll Sum=0;
forl(j,bl[i].L,bl[i].R)
Sum+=a[j],b[j]=i;
forl(j,bl[i].L+1,bl[i].R)
{
if(a[bl[i].L]==a[j])
bl[i].fir++;
else
break;
}
bl[i].fir++;
forr(j,bl[i].R-1,bl[i].L)
{
if(a[bl[i].R]==a[j])
bl[i].beh++;
else
break;
}
ll sum=0,Maxn=0;
forl(j,bl[i].L,bl[i].R)
{
if(a[j]==1)
sum++;
else
Maxn=max(Maxn,sum),sum=0;
}
bl[i].max1=max(Maxn,sum);
sum=0,Maxn=0;
forl(j,bl[i].L,bl[i].R)
{
if(a[j]==0)
sum++;
else
Maxn=max(Maxn,sum),sum=0;
}
bl[i].max0=max(Maxn,sum);bl[i].max0pd=1;bl[i].max1pd=1;
bl[i].beh++;
bl[i].sum=Sum;
bl[i].fugai=-1;
bl[i].len=bl[i].R-bl[i].L+1;
if(a[bl[i].L])
bl[i].firpd=1;
if(a[bl[i].R])
bl[i].behpd=1;
if(bl[i].R==n)
break;
}
while(m--)
{
ll opt,l,r;
cin>>opt>>l>>r;
l++,r++;
if(opt==0)
upd1(l,r);
else if(opt==1)
upd2(l,r);
else if(opt==2)
upd3(l,r);
else if(opt==3)
cout<<query1(l,r)<<endl;
else
cout<<query2(l,r)<<endl;
/* forl(i,1,n)
upd(i);
forl(i,1,n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496 718
4 159 328
3 430 951
4 706 758
6
282
5
*/
int main()
{
// IOS;
t=1;
// cin>>t;
while(t--)
solve();
/******************/
/*while(L<q[i].l) */
/* del(a[L++]);*/
/*while(L>q[i].l) */
/* add(a[--L]);*/
/*while(R<q[i].r) */
/* add(a[++R]);*/
/*while(R>q[i].r) */
/* del(a[R--]);*/
/******************/
QwQ;
}
/*
*/
/*
100 16
0 0 1 1 1 1 1 1 1 1 0 0 1 0 0 1 1 1 0 1 0 1 1 0 1 0 1 0 1 0 0 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 1 1 1 0 0 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 1 1 0 1 0 1 1 1 0 0 1 0 1
1 48 66
0 62 92
0 25 29
2 64 81
2 3 36
3 6 33
1 9 38
0 63 85
2 22 48
2 38 71
4 94 94
4 56 84
0 44 93
0 38 61
1 27 43
4 51 96
15
1
10
1
*/
/*
100 4
0 0 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 1 1 1 0 0 1 1 0 1 0 1 1 0 0 1 0 1 0 0 0 1 1 0 0 1 0 0 0 1 1 1 1 1 0 1 0 1 0 0 0 0 1 1 1 1 1 0 1 1 0
2 36 46
4 76 89
1 76 97
4 42 67
5
6
*/
/*
10 10
1 0 1 0 1 1 0 0 1 1
2 7 7
2 2 9
4 8 9
0 7 7
1 8 8
1 1 9
2 3 9
0 8 8
4 3 4
1 8 8
0
0
*/
/*
10 10
1 0 1 1 1 0 0 0 0 0
3 4 5
1 2 5
4 4 4
0 8 9
0 7 8
1 6 7
4 5 9
1 2 6
4 0 5
3 9 9
1
1
3
4
0
*/
/*
10 10
0 0 1 1 1 1 1 0 0 0
0 1 3
3 1 9
2 4 9
1 3 7
0 1 4
1 3 7
1 0 0
2 3 4
2 4 7
4 2 9
3
2
*/
/*
20 20
0 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 0 0 0
4 5 8
4 1 8
4 7 7
4 0 8
3 3 6
4 0 8
1 0 9
3 0 2
2 6 9
0 3 7
1 0 8
0 2 4
2 9 9
3 3 3
0 0 7
1 1 6
1 1 4
1 0 6
3 4 8
3 1 7
4
4
1
4
3
4
3
0
4
6
*/
最需要注意的就是操作 \(4\) 了,这里我来提供几组 hack 数据:
若您使用分块做法,将块长调为 pow(sqrt(n),0.66)
后食用以下几组数据效果更佳。
1:
in:
1000 6
1 1 0 1 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 0 0 1 0 0 1 1 0 0 0 1 1 0 1 1 1 1 0 1 0 1 1 1 0 0 0 1 1 0 0 1 0 1 0 1 1 1 0 0 1 1 0 1 0 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0 1 1 0 0 0 1 0 1 1 0 1 0 1 0 1 0 0 1 1 1 1 0 0 0 1 0 0 0 1 1 1 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 1 1 0 1 0 1 0 0 0 1 0 1 1 0 1 0 1 1 0 1 0 1 1 0 1 1 0 0 0 0 1 1 0 1 0 1 1 0 0 0 0 0 0 0 1 0 1 1 1 0 1 1 0 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 0 1 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 1 0 1 0 1 1 1 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 1 0 1 1 1 0 0 0 1 1 0 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 1 1 0 0 1 0 1 1 0 0 1 1 1 1 1 1 0 1 0 0 1 0 1 0 0 1 1 1 1 1 1 0 0 1 0 1 0 1 0 1 1 0 1 0 1 0 0 0 1 0 0 1 0 0 0 1 1 0 1 1 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 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6
4 0 5
3 9 9
out:
1
1
3
4
0
6:
in:
10 10
0 0 1 1 1 1 1 0 0 0
0 1 3
3 1 9
2 4 9
1 3 7
0 1 4
1 3 7
1 0 0
2 3 4
2 4 7
4 2 9
out:
3
2
7:
in:
20 20
0 1 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 0 0 0
4 5 8
4 1 8
4 7 7
4 0 8
3 3 6
4 0 8
1 0 9
3 0 2
2 6 9
0 3 7
1 0 8
0 2 4
2 9 9
3 3 3
0 0 7
1 1 6
1 1 4
1 0 6
3 4 8
3 1 7
out:
4
4
1
4
3
4
3
0
4
6
标签:洛谷,forl,bl,Sum,len,id,sum,杂题,P2572
From: https://www.cnblogs.com/wangmarui/p/18070364