思路

重题

代码

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
#define ls rt<<1
#define rs rt<<1|1
#define ll long long
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
const int maxn = 2e5 + 7;
int read() {
int x = 0, f = 1; char s = getchar();
for (; s < '0' || s > '9'; s = getchar()) if (s == '-') f = -1;
for (; s >= '0' && s <= '9'; s = getchar()) x = x * 10 + s - '0';
return x * f;
}
int n, m;
struct node{
int l,r,size,sum,lazy;
}e[maxn<<2];
void pushup(int rt) {
e[rt].sum=e[ls].sum+e[rs].sum;
}
void pushdown(int rt) {
if(e[rt].lazy%2) {
e[ls].lazy++;
e[rs].lazy++;
e[ls].sum=e[ls].size-e[ls].sum;
e[rs].sum=e[rs].size-e[rs].sum;
e[rt].lazy=0;
}
}
void build(int l,int r,int rt) {
e[rt].l=l,e[rt].r=r,e[rt].size=r-l+1;
if(l==r) return;
int mid=(l+r)>>1;
build(l,mid,ls);
build(mid+1,r,rs);
pushup(rt);
}
void modfity(int L,int R,int rt) {
if(L<=e[rt].l&&e[rt].r<=R) {
e[rt].sum=e[rt].size-e[rt].sum;
e[rt].lazy++;
return;
}
pushdown(rt);
int mid=(e[rt].l+e[rt].r)>>1;
if(L<=mid) modfity(L,R,ls);
if(R>mid) modfity(L,R,rs);
pushup(rt);
}
int query(int L,int R,int rt) {
if(L<=e[rt].l&&e[rt].r<=R) {
return e[rt].sum;
}
pushdown(rt);
int mid=(e[rt].l+e[rt].r)>>1,ans=0;
if(L<=mid) ans+=query(L,R,ls);
if(R>mid) ans+=query(L,R,rs);
return ans;
}
int main() {
n=read(),m=read();
build(1,n,1);
FOR(i,1,m) {
int p=read(),x=read(),y=read();
if(p) {
printf("%d\n",query(x,y,1));
} else {
modfity(x,y,1);
}
}
return 0;
}

最新文章

  1. iOS10 适配问题-Xcode8
  2. CSS样式表基础
  3. 【原】iOS学习之UIStoryboardSegue解析
  4. centos 配置 ssl服务
  5. 处理某个json文件的代码
  6. CyclicBarrier类合唱演绎
  7. oc中的枚举定义
  8. 在matlab中对hsv进行均匀量化和非均匀量化
  9. AS-demo09
  10. leetcode 119
  11. 如何在linux中配置PHP环境
  12. UILabel自适应高度,自动换行
  13. Unity的Cover flow的实现包(2个)
  14. HDU 4893 Wow! Such Sequence!(2014年多校联合 第三场 G)(线段树)
  15. CentOS下源码安装vsftpd-3.0.0,并设置指定用户访问指定目录(附带完整配置文件)
  16. 机器学习基石:Homework #0 SVD相关&amp;常用矩阵求导公式
  17. Win7系统下,docker构建nginx+php7环境实践
  18. Java学习笔记二:数据类型II
  19. HDU - 4456 cdq
  20. springJDBC和SpringJDBCTemplate解决方案探究

热门文章

  1. Kubernetes网络的4种解决方案
  2. android返回到第一个activity
  3. excel用法
  4. 配置tomcat通过客户端访问
  5. 自定义WordPress文件上传路径
  6. PHP学习必读的20本书
  7. 共用tableview一个继承类里面有
  8. B*树的定义
  9. sql查询一列 重复的数据
  10. Impala shell详解