【题目链接】

点击打开链接

【算法】

线段树,注意数据量大,要动态开点

【代码】

#include<bits/stdc++.h>
using namespace std;
const int MAXN = ; int n,q,l,r,opt,size = ,root = ;
struct Node {
int lc,rc,tag,sum;
} Tree[MAXN]; template <typename T> inline void read(T &x) {
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
}
template <typename T> inline void writeln(T x) {
write(x);
puts("");
} inline void push_up(int root) {
Tree[root].sum = Tree[Tree[root].lc].sum + Tree[Tree[root].rc].sum;
}
inline void push_down(int l,int r,int root) {
int mid = (l + r) >> ;
if (Tree[root].tag != -) {
if (!Tree[root].lc) Tree[root].lc = ++size;
if (!Tree[root].rc) Tree[root].rc = ++size;
Tree[Tree[root].lc].tag = Tree[Tree[root].rc].tag = Tree[root].tag;
Tree[Tree[root].lc].sum = Tree[root].tag * (mid - l + );
Tree[Tree[root].rc].sum = Tree[root].tag * (r - mid);
Tree[root].tag = -;
}
}
inline void modify(int &root,int l,int r,int ql,int qr,int val) {
int mid;
if (!root) root = ++size;
if (l == ql && r == qr) {
Tree[root].sum = val * (r - l + );
Tree[root].tag = val;
return;
}
push_down(l,r,root);
mid = (l + r) >> ;
if (mid >= qr) modify(Tree[root].lc,l,mid,ql,qr,val);
else if (mid + <= ql) modify(Tree[root].rc,mid+,r,ql,qr,val);
else {
modify(Tree[root].lc,l,mid,ql,mid,val);
modify(Tree[root].rc,mid+,r,mid+,qr,val);
}
push_up(root);
} int main() { read(n); read(q);
while (q--) {
read(l); read(r); read(opt);
if (opt == ) modify(root,,n,l,r,);
else modify(root,,n,l,r,);
writeln(n - Tree[].sum);
} return ; }

最新文章

  1. WizNote for linux installation
  2. 处理链方式执行APD处理
  3. spring - ioc和aop
  4. C/C++内存分配区
  5. 【转】Linux Soclet编程
  6. Appium入门示例(python)
  7. 麒麟OS剽窃
  8. hifi/ headphone test
  9. AIX 添加开机启动项
  10. 上传文件格式控制的困惑(application/octet-stream 限制不了BAT等格式上传)问题解决
  11. OSChina 的全文搜索设计说明 —— 索引过程
  12. cocos2d-x的A*寻路
  13. Netty+Tomcat热部署端口占用解决办法(转)
  14. Windows系统前端常用PS快捷键:
  15. php生成Excel表格
  16. jsp fmt标签详解
  17. mysql varchar和char的根本区别深度详解
  18. TensorFlow初探之简单神经网络训练mnist数据集(TensorFlow2.0代码)
  19. caffe训练脚本文件时遇到./build/tools/caffe: not found
  20. 【消息队列】kafka是如何保证高可用的

热门文章

  1. 1284-Primitive Roots,学信安的路过
  2. 洛谷P1021 邮票面值设计
  3. 【搜索】codeforces C. The Tag Game
  4. 【HDOJ6343】Graph Theory Homework(贪心)
  5. windows7 下安装使用memcached(二)
  6. UVA 11806 组合数学+容斥
  7. 2015轻院校赛 B 迷宫 (bfs)
  8. redis 实际应用中的缓存作用(转)
  9. 微信小程序-setData()方法
  10. Javascript 运行机制