Just a Hook(区间set)
Just a Hook
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 29106 Accepted Submission(s): 14396
Now Pudge wants to do some operations on the hook.
Let us number the consecutive metallic sticks of the hook from 1 to N. For each operation, Pudge can change the consecutive metallic sticks, numbered from X to Y, into cupreous sticks, silver sticks or golden sticks.
The total value of the hook is calculated as the sum of values of N metallic sticks. More precisely, the value for each kind of stick is calculated as follows:
For each cupreous stick, the value is 1.
For each silver stick, the value is 2.
For each golden stick, the value is 3.
Pudge wants to know the total value of the hook after performing the operations.
You may consider the original hook is made up of cupreous sticks.
For each case, the first line contains an integer N, 1<=N<=100,000, which is the number of the sticks of Pudge’s meat hook and the second line contains an integer Q, 0<=Q<=100,000, which is the number of the operations.
Next Q lines, each line contains three integers X, Y, 1<=X<=Y<=N, Z, 1<=Z<=3, which defines an operation: change the sticks numbered from X to Y into the metal kind Z, where Z=1 represents the cupreous kind, Z=2 represents the silver kind and Z=3 represents the golden kind.
10
2
1 5 2
5 9 3
#include<bits/stdc++.h>
#define N 100005
#define lson i*2,l,m
#define rson i*2+1,m+1,r
#define ll long long
using namespace std;
long long sum[N*];
long long setv[N*];
void pushup(int i)
{
sum[i]=sum[i*]+sum[i*+];
} void pushdown(int i,int num)
{
if(setv[i])
{
sum[i*]=setv[i]*(num-num/);
sum[i*+]=setv[i]*(num/);
setv[i*]=setv[i];
setv[i*+]=setv[i];
setv[i]=;
}
} void build(int i,int l,int r)
{
setv[i]=;
sum[i]=;
if(l==r)
return ;
int m=(l+r)/;
build(lson);
build(rson);
pushup(i);
} void update(int ql,int qr,int val,int i,int l,int r)
{
if(ql<=l&&r<=qr)
{
setv[i]=val;
sum[i]=val*(r-l+);
return ;
}
pushdown(i,r-l+);
int m=(l+r)/;
if(m>=ql) update(ql,qr,val,lson);
if(m<qr) update(ql,qr,val,rson);
pushup(i);
} ll query(int ql,int qr,int i,int l,int r)
{
//cout<<"l="<<l<<" r="<<r<<endl;
if(ql<=l&&r<=qr)
{
return sum[i];
}
pushdown(i,r-l+);
int m=(l+r)/;
ll cur=;
if(m>=ql) cur+=query(ql,qr,lson);
if(m<qr) cur+=query(ql,qr,rson);
//cout<<cur<<endl;
return cur;
} int t,n,q;
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
scanf("%d",&t);
for(int Case=;Case<=t;Case++)
{
scanf("%d",&n);
build(,,n);
//for(int i=1;i<18;i++)
// cout<<sum[i]<<" ";
//cout<<endl;
int a,b,c;
scanf("%d",&q);
while(q--)
{
scanf("%d%d%d",&a,&b,&c);
//cout<<a<<" "<<b<<" "<<c<<endl;
update(a,b,c,,,n);
}
printf("Case %d: The total value of the hook is %lld.\n",Case,query(,n,,,n));
}
return ;
}
Just a Hook(区间set)的更多相关文章
- HDU1698 Just a Hook (区间更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 1698 Just a Hook 区间更新 lazy标记
lazy标记 #include <iostream> #include <cstdio> #include <cstring> #include <sstre ...
- 线段树入门&lazy思想
线段树将区间分成若干个子区间,子区间又继续分,直到区间为一个点(区间左值等于右值) 对于父区间[a,b],其子区间为[a,(a+b)/2]和[(a+b)/2+1,b] 用于求区间的值,如区间最值.区间 ...
- HDU 1698 Just a Hook(线段树 区间替换)
Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...
- HDU 1698 Just a Hook(线段树/区间更新)
题目链接: 传送门 Minimum Inversion Number Time Limit: 1000MS Memory Limit: 32768 K Description In the g ...
- HDU1698Just a Hook(线段树 + 区间修改 + 求和)
题目链接 分析:1-N区间内初始都是1,然后q个询问,每个询问修改区间[a,b]的值为2或3或者1,统计最后整个区间的和 本来想刷刷手速,结果还是写了一个小时,第一个超时,因为输出的时候去每个区间查找 ...
- hdu 1698:Just a Hook(线段树,区间更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 1698 Just a Hook(线段树区间替换)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 1698 Just a Hook (线段树区间更新)
题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...
- HDU 1698 (线段树 区间更新) Just a Hook
有m个操作,每个操作 X Y Z是将区间[X, Y]中的所有的数全部变为Z,最后询问整个区间所有数之和是多少. 区间更新有一个懒惰标记,set[o] = v,表示这个区间所有的数都是v,只有这个区间被 ...
随机推荐
- java类成员的访问权限
private:这是安全级别最高的访问权限,尽在该类中可以访问到: 默认访问权限:又称包访问权限,顾名思义,仅在该包内可以访问: protected:在包访问权限的基础上,该类的子类也可以访问到: p ...
- windows 结束进程的详细过程
windows上如何结束进程的详细过程,下面附详细,图文说明 在cmd下,输入 netstat -ano|findstr 8080 //说明:查看占用8080端口的进程 在cmd下, ...
- JDFS:一款分布式文件管理系统,第四篇(流式云存储续篇)
一 前言 本篇博客是JDFS系列博客的第四篇,从最初简单的上传.下载,到后来加入分布式功能,背后经历了大量的调试,尤其当实验的虚拟计算结点数目增加后,一些潜在的隐藏很深的bug就陆续爆发.在此之前笔者 ...
- 调用惯例Calling Convention (或者说:调用约定)
调用惯例影响执行效率,参数的传递方式以及栈清除的方式. 调用惯例 参数传递顺序 谁负责清除参数 参数是否使用暂存器 register 从左到右 被调用者 是 pascal 从左到右 被调用者 否 ...
- PHP浮点型(float)转换为整形(int)/round()保留小数点后几位
round(x,y); x:需要转换的变量 y:保留几位小数 <?php echo round(3.112312321) //输出3 echo round(3.112312321,3) //输出 ...
- Python自学笔记-生成器(来自廖雪峰的官网Python3)
感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. 生成器 通过列 ...
- 使用jquery-qrcode在页面上生成二维码,支持中文
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- style里的文字 背景 样式以及边框
<style> body{background:#FCC;} .c00 div{ margin:0 auto; padding:0;} #a01{ ...
- CoreData归纳使用
1.CoreData简介 2.CoreData数据模型 3.CoreData的主要对象 4.使用CoreData实现数据存储 一.CoreData简介 CoreData用做数据持久化,是数据持久化的最 ...
- C# 解析 sln 文件
我的项目,编码工具 需要检测打开一个工程,获取所有项目. 但是发现原来的方法,如果存在文件夹,把项目放在文件夹中,那么是无法获得项目,于是我就找了一个方法去获得sln文件的所有项目. 原先使用的方法d ...