分析:https://www.bilibili.com/read/cv4777102 #include <cstdio> #include <algorithm> using namespace std; ; ]; int L,R,C,n,m,q; #define ls t[x].l #define rs t[x].r ;))ans++;return ans;} ;} void update(int x){t[x].color=t[ls].color|t[rs].color;}…
发现自己越来越傻逼了.一道傻逼题搞了一晚上一直超时,凭啥子就我不能过??? 然后发现cin没关stdio同步... Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. There is a very long board with length…
题目描写叙述: 长度为L个单位的画板,有T种不同的颜料.现要求按序做O个操作,操作分两种: 1."C A B C",即将A到B之间的区域涂上颜色C 2."P A B".查询[A,B]区域内出现的颜色种类 出现操作2时.请输出答案 PS:初始状态下画板颜色为1 一開始没有想那么好,用int整型位移来取代颜色.还是使用了最传统的bool color[来记录.但是不知道错在了哪里. #include<iostream> #include<cstdio&g…
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39917 Accepted: 12037 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. The…
题目链接:  poj 2777 Count Color 题目大意:  给出一块长度为n的板,区间范围[1,n],和m种染料 k次操作,C  a  b  c 把区间[a,b]涂为c色,P  a  b 查询区间[a,b]有多少种不同颜色 解题思路:  很明显的线段树的区间插入和区间查询,但是如何统计有多少不同的颜色呢? 如果每个结点数组来存储颜色的种类,空间复杂度很高,而且查询很慢 颜色最多只有30种,可以用位运算中的“按位或|” 颜色也用二进制来处理,和存储: 第一种颜色的二进制表示1 第二种颜色…
题目地址:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30995   Accepted: 9285 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of pr…
Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33311 Accepted: 10058 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. The…
A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 92921   Accepted: 28910 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 42472   Accepted: 12850 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. There is a…
You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edges are numbered 1 through N − 1. Each edge is associated with a weight. Then you are to execute a series of instructions on the tree. The instructions can be one…
Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 38921   Accepted: 11696 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem.…
题目链接:https://nanti.jisuanke.com/t/40852 题意:给定一个01串s,进行m次操作,|s|<=1e6,m<=5e5 操作有两种 l r 0,区间[l,r]升序排序 l r 1,区间[l,r]降序排序 输出m次操作后的串s 官方解析: 维护区间1的个数,区间0的个数=区间长度-区间1的个数,完成区间赋值操作并更新即可. 个人思路: 线段树的操作都是log(n),如果带了lazy标记,就可以小于log(n),不必查询到每个点.例如将[1,3]都置为1,只用将t[2…
题目链接:http://poj.org/problem?id=2777 题意是有L个单位长的画板,T种颜色,O个操作.画板初始化为颜色1.操作C讲l到r单位之间的颜色变为c,操作P查询l到r单位之间的颜色有几种. 很明显的线段树成段更新,但是查询却不好弄.经过提醒,发现颜色的种类最多不超过30种,所以我们用二进制的思维解决这个问题,颜色1可以用二进制的1表示,同理,颜色2用二进制的10表示,3用100,....假设有一个区间有颜色2和颜色3,那么区间的值为二进制的110(十进制为6).那我们就把…
Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new problem. There is a very long board with length L centimeter, L is a positive integer, so we can evenly d…
Count Color Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems. Here, we get a new pr…
pid=1698">题目请点我 题解: 接触到的第一到区间更新,须要用到lazy标记.典型的区间着色问题. lazy标记详情请參考博客:http://ju.outofmemory.cn/entry/99351 简单讲就是被lazy标记的非叶子节点所包括的全部叶子节点具有同样的性质.当更新或查询到该区间时,不再向下递归.仅对当前节点的lazy标记进行改动. update : 假设当前区间刚好全然在目的区间内:看当前节点是否被标记.若未被标记.或者被标记了可是与要更新类型同样,不再向下更新.仅…
Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 32434    Accepted Submission(s): 15927 Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing…
1081 线段树练习 2 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 大师 Master   题目描述 Description 给你N个数,有两种操作 1:给区间[a,b]的所有数都增加X 2:询问第i个数是什么? 输入描述 Input Description 第一行一个正整数n,接下来n行n个整数,再接下来一个正整数Q,表示操作的个数. 接下来Q行每行若干个整数.如果第一个数是1,后接3个正整数a,b,X,表示在区间[a,b]内每个数增加X,如果是2,后面跟1个整数i,…
Nice boat Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 335    Accepted Submission(s): 159 Problem Description There is an old country and the king fell in love with a devil. The devil al…
lazy写崩了--. 查了好久 /* U-> [l,r]–>1 I-> [1,l-1] [r+1,+无穷] –>0 D-> [l,r]–>0 C-> [1,l-1] [r+1,+无穷]–>0 xor[l,r] S-> [l,r]–>xor */ //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using names…
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define INF 0X3f3f3f3f ; ; ll a[MAXN]; struct node { int left, right; //区间端点 ll max, sum; //看题目要求 ll lazy; void update(ll x) { sum += (right - left +…
题目连接   http://codevs.cn/problem/1082/ Description 给你N个数,有两种操作: 1:给区间[a,b]的所有数增加X 2:询问区间[a,b]的数的和. Input 第一行一个正整数n,接下来n行n个整数, 再接下来一个正整数Q,每行表示操作的个数, 如果第一个数是1,后接3个正整数, 表示在区间[a,b]内每个数增加X,如果是2, 表示操作2询问区间[a,b]的和是多少. 输出描述 Output Description 对于每个询问输出一行一个答案 S…
题目: 寒假来了,又到了小明和女神们约会的季节.  小明虽为屌丝级码农,但非常活跃,女神们常常在小明网上的大段发言后热情回复“呵呵”,所以,小明的最爱就是和女神们约会.与此同时,也有很多基友找他开黑,由于数量实在过于巨大,怎么安排时间便成了小明的一大心事.  我们已知小明一共有T的空闲时间,期间会有很多女神或者基友来找小明.  作为一个操作系统曾经怒考71分的大神,小明想到了一个算法,即“首次适应算法”,根据操作系统课本的描述,就是找一段最靠前的符合要求的连续空间分配给每个请求,由此小明做出了一…
POJ 2777 Count Color --线段树Lazy的重要性 原题 链接:http://poj.org/problem?id=2777 Count Color Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 59087 Accepted: 17651 Description Chosen Problem Solving and Program design as an optional course, you are…
POJ 2777 Count Color (线段树)   Count Color Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29895   Accepted: 8919 Description Chosen Problem Solving and Program design as an optional course, you are required to solve all kinds of problems.…
题目描述 Description 给你N个数,有两种操作: 1:给区间[a,b]的所有数增加X 2:询问区间[a,b]的数的和. 输入描述 Input Description 第一行一个正整数n,接下来n行n个整数, 再接下来一个正整数Q,每行表示操作的个数, 如果第一个数是1,后接3个正整数, 表示在区间[a,b]内每个数增加X,如果是2, 表示操作2询问区间[a,b]的和是多少. pascal选手请不要使用readln读入 输出描述 Output Description 对于每个询问输出一行…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3397 题目大意: 0 a b表示a-b区间置为0 1 a b表示a-b区间置为1 2 a b表示a-b区间中的0变成1,1变成0 3 a b表示a-b区间中的1的数目 4 a b表示a-b区间中最长连续1的长度 解题思路: 线段树多种标记. 需要处理的东西比较多: 做题的时候发现一个问题: 我的宏定义Max不可以用于函数,尤其是递归函数,这样会使得同一函数重复调用好几遍,递归函数的话更会超时. #…
E. DZY Loves Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output DZY loves colors, and he enjoys painting. On a colorful day, DZY gets a colorful ribbon, which consists of n units (they…
A Simple Problem with Integers Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other i…
JuQueen Time Limit: 5 Sec  Memory Limit: 512 MB Description Input Output Sample Input 10 10 5 state 0 groupchange 2 9 7 state 9 groupchange 0 2 10 change 0 -5 Sample Output 0 7 7 3 -3 线段树lazy的巧用 #include <iostream> #include <cstdio> #include &…