hdu1698线段树
来源:互联网 发布:人工智能语音机器人 编辑:程序博客网 时间:2024/06/08 02:18
不知道怎么拖啊拖啊,三天前写的代码今天A了,然后。。。想说什么都不太记得起来了
这次的value值用来记录叶子们的颜色,如果叶子们是同色就记颜色,不同色就记-1,再由叶子们去解决颜色
计算的时候只要(a[i].r-a[i].l+1)*a[i].value就行了
什么时候我可以完全由自己写出一道不水的线段树题呢
感觉这道题蛮好,很灵活
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 100000+10;
struct node
{
int l,r,value;
}a[maxn<<2];
void build(int i,int l,int r)
{
a[i].l=l;
a[i].r=r;
a[i].value=1;
if(l==r)
return;
int mid=(l+r)/2;
build(i*2,l,mid);
build(i*2+1,mid+1,r);
}
void qurry(int i,int l,int r,int v)
{
if(a[i].value==v)
return;
if(a[i].l==l&&a[i].r==r)
{
a[i].value=v;
return;
}
if(a[i].value!=-1)
{
a[i*2].value=a[i*2+1].value=a[i].value;
a[i].value=-1;
}
int mid=(a[i].l+a[i].r)/2;
if(r<=mid)
qurry(i*2,l,r,v);
else if(l>mid)
qurry(i*2+1,l,r,v);
else
{
qurry(i*2,l,mid,v);
qurry(i*2+1,mid+1,r,v);
}
}
int find(int i)
{
if(a[i].value!=-1)
return (a[i].r-a[i].l+1)*a[i].value;
else
return find(i*2)+find(i*2+1);
}
int main()
{
int t,n,k,x,y,m;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
scanf("%d%d",&n,&k);
build(1,1,n);
while(k--)
{
scanf("%d%d%d",&x,&y,&m);
qurry(1,x,y,m);
}
printf("Case %d: The total value of the hook is %d.\n",i,find(1));
}
return 0;
}
/*
1
10
2
1 5 2
5 9 3
*/
- hdu1698(线段树)
- hdu1698之线段树
- hdu1698线段树
- HDU1698 线段树
- HDU1698(线段树)
- hdu1698线段树
- HDU1698(线段树LAZY)
- HDU1698 线段树
- HDU1698线段树区间更新
- 线段树区间修改hdu1698
- hdu1698 线段树区间更新
- hdu1698 线段树 区间更新
- HDU1698线段树区间更新
- hdu1698(线段树区间更新)
- 线段树区间更新hdu1698
- hdu1698 线段树区间更新
- HDU1698(线段树+延迟标记)
- HDU1698 线段树 区间更新
- mysql之 mysql数据库压力测试工具(mysqlslap)
- HMM学习最佳范例: 前向算法(Forward Algorithm)
- nginx问题定位之监控进程异常退出
- 禁用一个右下角广告弹窗的程序 popwndexe.exe
- 【MyEclipse】常用快捷键和功能设置
- hdu1698线段树
- JSONObject 转换 JSON复杂对象
- Java关于流的使用
- 拨号上网设置定时自动断网重连
- netty分割符和定长解码器的应用
- MySql 中 一次update更新多条数据
- eclips添加testNG框架
- 从url中提取域名的几种方法
- 翻转后的棋盘