【Codeforces 915E】 Physical Education Lessons
2024-08-30 17:06:21
【题目链接】
【算法】
线段树,注意数据量大,要动态开点
【代码】
#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 ; }
最新文章
- WizNote for linux installation
- 处理链方式执行APD处理
- spring - ioc和aop
- C/C++内存分配区
- 【转】Linux Soclet编程
- Appium入门示例(python)
- 麒麟OS剽窃
- hifi/ headphone test
- AIX 添加开机启动项
- 上传文件格式控制的困惑(application/octet-stream 限制不了BAT等格式上传)问题解决
- OSChina 的全文搜索设计说明 —— 索引过程
- cocos2d-x的A*寻路
- Netty+Tomcat热部署端口占用解决办法(转)
- Windows系统前端常用PS快捷键:
- php生成Excel表格
- jsp fmt标签详解
- mysql varchar和char的根本区别深度详解
- TensorFlow初探之简单神经网络训练mnist数据集(TensorFlow2.0代码)
- caffe训练脚本文件时遇到./build/tools/caffe: not found
- 【消息队列】kafka是如何保证高可用的