首页 技术 正文
技术 2022年11月15日
0 收藏 466 点赞 2,519 浏览 1027 个字

思路:

用线段树模拟题中的操作就好

(标记异或 长度=区间总长度-当前已开灯的长度)

//By SiriusRen
#include <cstdio>
using namespace std;
#define N 666666
int n,m,op,xx,yy,tree[N],lazy[N];
void push_down(int num,int pos){
int lson=pos<<1,rson=pos<<1|1;
tree[lson]=num-(num>>1)-tree[lson];
tree[rson]=(num>>1)-tree[rson];
lazy[lson]=!lazy[lson];
lazy[rson]=!lazy[rson];
lazy[pos]=0;
}
void insert(int l,int r,int pos){
if(l>=xx&&r<=yy){
tree[pos]=r-l+1-tree[pos];
lazy[pos]=!lazy[pos];
return;
}
if(lazy[pos])push_down(r-l+1,pos);
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
if(mid<xx)insert(mid+1,r,rson);
else if(mid>=yy)insert(l,mid,lson);
else insert(l,mid,lson),insert(mid+1,r,rson);
tree[pos]=tree[lson]+tree[rson];
}
int query(int l,int r,int pos){
if(l>=xx&&r<=yy)return tree[pos];
if(lazy[pos])push_down(r-l+1,pos);
int mid=(l+r)>>1,lson=pos<<1,rson=pos<<1|1;
if(mid<xx)return query(mid+1,r,rson);
else if(mid>=yy)return query(l,mid,lson);
else return query(l,mid,lson)+query(mid+1,r,rson);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d%d%d",&op,&xx,&yy);
if(!op)insert(1,n,1);
else printf("%d\n",query(1,n,1));
}
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,115
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,587
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,433
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,204
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,840
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,925