意甲冠军:

特定n多头排列。m操作

以下是各点的颜色

以下m一种操纵:

1 l r col 染色

2 l r col 问间隔col色点

== 通的操作+区间内最大最小颜色数的优化,感觉非常不科学。。。

==感觉能够卡掉这样的写法。。反正就是不科学嘛

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define L(x) tree[x].l
#define R(x) tree[x].r
#define Len(x) tree[x].len
#define Lazy(x) tree[x].lazy
#define M(x) tree[x].minn
#define W(x) tree[x].maxx
#define Lson(x) (x<<1)
#define Rson(x) (x<<1|1)
const int N = 100010;
struct node{int l, r, len, lazy, minn, maxx;
}tree[N<<2];
int col[N];
void push_up(int id){if(Lazy(Lson(id)) == Lazy(Rson(id)))Lazy(id) = Lazy(Lson(id));else Lazy(id) = -1;M(id) = min(M(Lson(id)), M(Rson(id)));W(id) = max(W(Lson(id)), W(Rson(id)));
}
void push_down(int id){if(Lazy(id) != -1){Lazy(Lson(id)) = Lazy(Rson(id)) = Lazy(id);M(Lson(id)) = W(Lson(id)) = Lazy(id);M(Rson(id)) = W(Rson(id)) = Lazy(id);}
}
void build(int l, int r, int id){L(id) = l; R(id) = r;Len(id) = r-l+1;Lazy(id) = -1;if(l == r){Lazy(id) = col[l];W(id) = M(id) = col[l];return ;}int mid = (l+r)>>1;build(l, mid, Lson(id));build(mid+1, r, Rson(id));push_up(id);
}
void updata(int l, int r,int val, int id){if(l == L(id) && R(id) == r){Lazy(id) = val;W(id) = M(id) = val;return ;}push_down(id);int mid = (L(id) + R(id)) >>1;if(mid < l)updata(l, r, val, Rson(id));else if(r <= mid)updata(l, r, val, Lson(id));else {updata(l, mid, val, Lson(id));updata(mid+1, r, val, Rson(id));}push_up(id);
}
int query(int l, int r, int col, int id){if(!(M(id)<=col && col<=W(id))) return 0;if(Lazy(id)!=-1){if(Lazy(id) == col)return r-l+1;else return 0;}push_down(id);int mid = (L(id) + R(id)) >>1;if(mid < l)return query(l, r, col, Rson(id));else if(r <= mid)return query(l, r, col, Lson(id));elsereturn query(l, mid, col, Lson(id)) + query(mid+1, r, col, Rson(id));
}
int n, que;int main() {while (cin>>n>>que) {for(int i = 1; i <= n; i++)scanf("%d", &col[i]);build(1, n, 1);while(que--){int type, l, r, color;scanf("%d %d %d %d", &type, &l, &r, &color);l++; r++;if(type == 1)updata(l, r, color, 1);elseprintf("%d\n", query(l, r, color, 1));}}return 0;
}
/*
5 12
1 2 3 4 0
2 1 3 3
1 1 3 1
2 1 3 3
2 0 3 1
2 3 4 1
1 0 4 0
2 0 4 0
2 0 4 2000000000
1 0 0 1
1 4 4 2
2 0 4 1
2 0 4 2*/

版权声明:本文博客原创文章。博客,未经同意,不得转载。

HDU 4391 Paint The Wall 段树(水相关推荐

  1. hdu 4391 Paint The Wall 线段树 +优化 2012 Multi-University Training Contest 10 )

    http://acm.hdu.edu.cn/showproblem.php?pid=4391 题意: 刷墙, 以开始 有 n个节点,每个节点有一种颜色 ,m 次询问 m次  输入 a,l,r,z 如果 ...

  2. HDU 6356.Glad You Came-线段树(区间更新+剪枝) (2018 Multi-University Training Contest 5 1007)...

    6356.Glad You Came 题意就是给你一个随机生成函数,然后从随机函数里确定查询的左右区间以及要更新的val值.然后最后求一下异或和就可以了. 线段树,区间最大值和最小值维护一下,因为数据 ...

  3. 计蒜客 28437.Big brother said the calculation-线段树+二分-当前第k个位置的数 ( ACM训练联盟周赛 M)...

    M. Big brother said the calculation 通过线段树维护. 这个题和杭电的一道题几乎就是一样的题目.HDU5649.DZY Loves Sorting 题意就是一个n的排 ...

  4. HDU 5792 World is Exploding (树状数组)

    World is Exploding 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 Description Given a sequence ...

  5. 【UVA】11992 - Fast Matrix Operations(段树模板)

    主体段树,要注意,因为有set和add操作,当慵懒的标志下推.递归优先set,后复发add,每次运行set行动add马克清0 WA了好几次是由于计算那一段的时候出问题了,可笑的是我对着模板找了一个多小 ...

  6. hdu1305 字典树水题

    题意:      给你一些字符串,然后问你他们中有没有一个串是另一个串的前缀. 思路:       字典树水题,(这种水题如果数据不大(这个题目不知道大不大,题目没说估计不大),hash下也行,把每个 ...

  7. C++Persistent segment tree持久段树的实现算法(附完整源码)

    C++Persistent segment tree持久段树的实现算法 C++Persistent segment tree持久段树的实现算法完整源码(定义,实现,main函数测试) C++Persi ...

  8. C语言实现段树segment tree(附完整源码)

    C语言实现段树segment tree 段树结构体定义 实现以下6个接口 完整实现和main测试源码 段树结构体定义 typedef struct segment_tree {void *root; ...

  9. HDU 1247 Hat’s Words 字典树(Trie树)

    HDU 1247 Hat's Words 字典树(Trie树) 字典树的建立是应该都是一样的 下面是我的做法: 建立完后, 对每一个单词都进行find_string()判断是否符合, 分别对其分成两半 ...

最新文章

  1. 用 .NET Memory Profiler 跟踪.net 应用内存使用情况--基本应用篇(转载)
  2. mysql-win安装教程,WINDOWS下安装MYSQL教程详解
  3. 96. 奇怪的汉诺塔【递推】
  4. SpringMVC札集(05)——SpringMVC参数回显
  5. 有效的Java –所有对象通用的方法
  6. 前端学习(1741):前端调试值之元素状态改变的监听方法
  7. java web应用程序_说说Java Web中的Web应用程序|乐字节
  8. 小米的服务器地址怎么修改,小米无线路由器IP地址怎么修改
  9. 思维导图工具之Freeplane(上篇)
  10. Win PE 启动盘制作
  11. 南京大学交叉培养计算机与金融招生人数,教务处组织召开计算机与金融工程实验班师生见面会...
  12. 分布式系统的知识点-架构设计
  13. HTML5期末大作业:美妆网页主题网站设计——清新的手工肥皂网站展示(4页)HTML+CSS+JavaScript...
  14. JAVA移动垃圾分类车管理平台计算机毕业设计Mybatis+系统+数据库+调试部署
  15. php输出3d彩票号码,3D彩票开出罕见“豹子号“!彩票中心要“赔钱”
  16. 支付宝支付申请流程,配置过程
  17. Android 原生控件之一 TextView
  18. 网易易盾流量多发反外挂落地实践
  19. 乌云安全所有资料(百度云打包)pdf
  20. 常规密码学加解密脚本(python)

热门文章

  1. 用一条sql取得第10到第20条的记录-Mssql数据库
  2. 完成一个MVC+Nhibernate+Jquery-EasyUI信息发布系统
  3. JavaScript 入门基础 (八)
  4. ASP.net获取当前url各种属性(文件名、参数、域名 等)的方法
  5. [转]symbian基本类型转换
  6. UVA11389巴士司机问题
  7. hdu4396 多状态spfa
  8. 【字符串】最长回文子串 ( 蛮力算法 )
  9. 【Flutter】Flutter 拍照示例 ( Android 应用兼容 Android X | Gradle 版本号 | Gradle 插件版本号 | Android X 支持 | SDK 版本 )
  10. 【计算机网络】计算机网络 OSI 参考模型 与 TCP/IP 参考模型 对比