lndjy @ 2020-03-20 08:10:37
RT
#include<iostream>
#include<cstdio>
#include<set>
#define IT set<node>::iterator
using namespace std;
int inline read()
{
int ans=0,f=1;
char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(isdigit(ch))
{
ans=ans*10+ch-'0';
ch=getchar();
}
return ans*f;
}
int n,m;
bool a[100005];
struct node
{
int l,r;
mutable bool f;
bool operator <(const node &p)
const{
return l<p.l;
}
};
set<node> s;
IT split(int pos)
{
IT it=s.lower_bound((node){pos,-1,0});
if(it!=s.end()&&it->l==pos) return it;
it--;
int l=it->l,r=it->r,f=it->f;
s.erase(it);
s.insert((node){l,pos-1,f});
return s.insert((node){pos,r,f}).first;
}
void tuiping(int l,int r,int f)
{
IT itr=split(r+1),itl=split(l);
s.erase(itl,itr);
s.insert((node){l,r,f});
}
void change(int l,int r)
{
IT itr=split(r+1),itl=split(l);
for(;itl!=itr;itl++) itl->f=!(itl->f);
}
int asksum(int l,int r)
{
IT itr=split(r+1),itl=split(l);
int ans=0;
for(;itl!=itr;itl++)
ans+=itl->f*(itl->r-itl->l+1);
return ans;
}
int askmax(int l,int r)
{
IT itr=split(r+1),itl=split(l);
int ans=0,sum=0;
for(;itl!=itr;itl++)
{
if(itl->f==1) sum+=itl->r-itl->l+1;
ans=max(ans,sum);
if(itl->f==0) sum=0;
}
return ans;
}
void write(int x)
{
if(x/10)
write(x/10);
putchar('0'+(x%10));
}
int main()
{
n=read();m=read();
for(int i=1;i<=n;i++)
a[i]=read();
for(int i=1;i<=n;i++)
s.insert((node){i,i,a[i]});
s.insert((node){n+1,n+1,0});
for(int i=1;i<=m;i++)
{
int op=read(),l=read()+1,r=read()+1;
if(op==0) tuiping(l,r,0);
if(op==1) tuiping(l,r,1);
if(op==2) change(l,r);
if(op==3) write(asksum(l,r)),putchar('\n');
if(op==4) write(askmax(l,r)),putchar('\n');
}
return 0;
}
by lndjy @ 2020-03-20 08:12:13
只有30分,TLE
by IntrepidStrayer @ 2020-03-20 08:14:41
qndjr
by lndjy @ 2020-03-20 08:16:19
@abcdefg123456 但是题解有ODT啊qwq
by IntrepidStrayer @ 2020-03-20 08:19:10
register,火车头
by OIforJoy @ 2020-03-20 08:19:37
据说原来不卡但是NaCly_Fish改了数据...
by lndjy @ 2020-03-20 08:20:35
@abcdefg123456 改了数据为什么题面不写啊qwq
by OIforJoy @ 2020-03-20 08:22:34
这个就不知道了...你翻翻讨论区
by Vocalise @ 2020-04-28 12:48:36
考古+也是30分打死过不掉
by KarL05 @ 2020-08-06 16:21:53
++