当前位置: 首页 > news >正文

南康网站建设免费收录链接网

南康网站建设,免费收录链接网,石家庄网站托管公司,pbootcms的特点题意:一段线段由n条小线段组成,每次操作把一个区间的小线段变成金银铜之一(金的价值为3,银为2,铜为1),最初可当做全为铜;最后求这条线段的总价值。 思路:区间更新。 区…

题意:一段线段由n条小线段组成,每次操作把一个区间的小线段变成金银铜之一(金的价值为3,银为2,铜为1),最初可当做全为铜;最后求这条线段的总价值。

思路:区间更新。

区间更新思路:   更新时,把无代表性的父节点标记成0,

 把要更新的父节点的旧状态甩给下一层,

 然后再向下更新就行。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int MAXN=100000;
int tree[3*MAXN+10],v,st,en;
int ans;
void update(int root,int n_left,int n_right){int mid=(n_left+n_right)/2;if(n_left>=st&&n_right<=en){tree[root]=v;}else{if(tree[root]){//把当前层的状态甩给下一层tree[root*2]=tree[root*2+1]=tree[root];tree[root]=0;}if(mid<st){update(root*2+1,mid+1,n_right);}else if(mid>=en){update(root*2,n_left,mid);}else{update(root*2,n_left,mid);update(root*2+1,mid+1,n_right);}}return ;
}
void query(int root,int n_left,int n_right){int mid=(n_left+n_right)/2;if(tree[root]!=0){ans+=(n_right-n_left+1)*tree[root];return ;}query(root*2,n_left,mid);query(root*2+1,mid+1,n_right);return ;
}
int main()
{int T;cin>>T;int cut=0;while(T--){cut++;memset(tree,0,sizeof(tree));int m,n;cin>>n>>m;st=1;en=n;v=1;update(1,1,n);while(m--){scanf("%d%d%d",&st,&en,&v);update(1,1,n);}ans=0;query(1,1,n);cout<<"Case "<<cut<<": The total value of the hook is "<<ans<<'.'<<endl;}
}

Description

In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length. 



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. 

Input

The input consists of several test cases. The first line of the input is the number of the cases. There are no more than 10 cases. 
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. 

Output

For each case, print a number in a line representing the total value of the hook after the operations. Use the format in the example. 

Sample Input

1
10
2
1 5 2
5 9 3

Sample Output

Case 1: The total value of the hook is 24.

http://www.lbrq.cn/news/2409139.html

相关文章:

  • 网站目录权限 user百度云搜索资源入口
  • 网页策划方案怎么做windows优化大师怎么样
  • 八年级信息上册如何做网站百度文库个人登录
  • 网站建设的工作在哪里找客户资源推广价格一般多少
  • wordpress个人网站主题神马搜索推广
  • 免费好用的crm系统淘宝网店的seo主要是什么
  • 美橙网站建设经典案例如何网络推广
  • 网站建设导航栏钟南山今天感染新冠了
  • 网页版传奇世界什么组合最好seo具体seo怎么优化
  • 网站建设任务执行书app推广拉新
  • 如何与老板谈网站建设深圳网络推广团队
  • 腾讯用户体验网站广告网络推广怎么做
  • 两学一做教育网站宁波seo公司排名榜
  • 建筑兼职招聘网广州谷歌优化
  • 无锡建行网站描述建设一个网站的具体步骤
  • 优秀个人网站模板下载免费推广网站平台
  • 做网站哪家网站好艺人百度指数排行榜
  • 网站程序源码上传到空间打开网站首页还是显示的程序原源代码seo排名点击首页
  • 东莞新闻头条新闻今天seo软文代写
  • 做网站是个什么行业app拉新一手渠道
  • 做妈妈网站怎么赚钱优化大师官方下载
  • 花桥做网站合肥网站排名推广
  • 服务企业建设网站泉州关键词优化报价
  • 做盗版小说网站违法吗网站外链出售
  • e龙岩官网下载seo结算系统
  • 网站点赞怎么做的网络外贸推广
  • 2m带宽可以做音乐网站免费做网站的平台
  • logo制作步骤seo是什么意思的缩写
  • 锦州建设工程信息网站优化网站哪个好
  • 石家庄造价信息网杭州seo运营
  • 芯谷科技--固定电压基准双运算放大器D4310
  • 数据结构与算法汇总
  • Linux系统中全名、用户名、主机名的区别
  • 【GameMaker】GML v3 的现行提案
  • week4
  • 使用 Pyecharts 绘制精美饼状图:从基础到高级技巧