啷里个浪 @ 2021-12-09 09:54:36
造数据:
自己测的时候可以把n、m开小,n到10、m到20就行
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
using namespace std;
int main(){
srand(time(0));
int n=rand()%100+1;
cout<<n<<" ";
int m=rand()%200+1;
cout<<m<<endl;
for(int i=1;i<=n;i++)cout<<rand()%2<<" ";cout<<endl;
for(int i=1;i<=m;i++){
int op=rand()%5;
int l=rand()%n,r=rand()%n;
if(l>r)swap(l,r);
cout<<op<<" "<<l<<" "<<r<<endl;
}
return 0;
}
暴力程序:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ls (x<<1)
#define rs (x<<1)|1
using namespace std;
const int N=1e5+10;
int n,m,a[N];
int main(){
IOS;
cin>>n;cin>>m;
for(int i=1;i<=n;i++)cin>>a[i];
for(int j=1;j<=m;j++){
int op,l,r;cin>>op>>l>>r;
++l;++r;
if(op==0)for(int i=l;i<=r;i++)a[i]=0;
else if(op==1)for(int i=l;i<=r;i++)a[i]=1;
else if(op==2)for(int i=l;i<=r;i++)a[i]^=1;
else if(op==3){
int ans=0;
for(int i=l;i<=r;i++)ans+=a[i];
cout<<ans<<endl;
}else if(op==4){
int f[N],ans=a[l];
f[l]=a[l];
for(int i=l+1;i<=r;i++)if(a[i]==1)f[i]=f[i-1]+1,ans=max(ans,f[i]);
else f[i]=0;
cout<<ans<<endl;
}
for(int i=1;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
}
return 0;
}
by Qiaoqia @ 2021-12-09 10:09:12
谢谢您!
by SDNetFriend @ 2021-12-09 11:15:28
平时对拍不都是直接去跟题解拍吗(雾)
by 啷里个浪 @ 2021-12-15 16:31:40
@SDNetFriend 考试没有题解拍啊(大雾)/手动狗头
by SDNetFriend @ 2021-12-15 16:55:51
@啷里个浪 现在也不是考试啊,考试我也收不到你的程序(狗头+1)
by 啷里个浪 @ 2021-12-15 17:09:09
@SDNetFriend 啊这,请叫我助人为乐的eleveni/手动狗头,当我手欠给小号换上eleveni的名字时,我就永远失去了叫eleveni的权利/滑稽
by gyyyyx @ 2022-02-02 10:17:28
太谢谢了!
by Yansuan_HCl @ 2022-02-08 13:20:42
感恩楼主
by sgly33 @ 2022-07-14 15:47:08
感谢!
by tybbs @ 2023-01-30 17:22:11
拜谢