hdu 1556 Color the ball(线段树区间维护+单点求值)
传送门:Color the ball
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 25511 Accepted Submission(s): 12393
当N = 0,输入结束。
1 1
2 2
3 3
3
1 1
1 2
1 3
0
3 2 1
题解:
线段树区间维护(水水水)
代码:
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define mem(arr, num) memset(arr, 0, sizeof(arr))
#define _for(i, a, b) for (int i = a; i <= b; i++)
#define __for(i, a, b) for (int i = a; i >= b; i--)
#define IO \
ios::sync_with_stdio(false); \
cin.tie(); \
cout.tie();
using namespace std;
typedef long long ll;
const ll inf = 0x3f3f3f3f;
;
const ll mod = 1000000007LL;
<< ;
int dat[N],n;
void update(int a,int b,int k,int l,int r) {
if(a<=l && b >= r) {
dat[k]++;
} else if(a <= r && b >=l) {
update(a,b,k<<,l,(l+r)/);
update(a,b,k<<|,(l+r)/+,r);
}
}
void down(int l,int r,int k) {
if(l==r) {
l==n?printf("%d\n",dat[k]):printf("%d ",dat[k]);
}
else {
dat[k<<] += dat[k];
dat[k<<|] += dat[k];
down(l,(l+r)/,k<<);
down((l+r)/+,r,k<<|);
}
}
int main() {
int a,b;
while(scanf("%d",&n),n) {
mem(dat,);
_for(i,,n) {
scanf("%d%d",&a,&b);
update(a,b,,,n);
}
down(,n,);
}
;
}
hdu 1556 Color the ball(线段树区间维护+单点求值)的更多相关文章
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hdu 1556 Color the ball 线段树 区间更新
水一下 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 ...
- hdu 1556 Color the ball (线段树+代码详解)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu 1556 Color the ball 线段树
题目链接:HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气 ...
- HDU 1556 Color the Ball 线段树 题解
本题使用线段树自然能够,由于区间的问题. 这里比較难想的就是: 1 最后更新须要查询全部叶子节点的值,故此须要使用O(nlgn)时间效率更新全部点. 2 截取区间不能有半点差错.否则答案错误. 这两点 ...
- hdu 1116 敌兵布阵 线段树 区间求和 单点更新
线段树的基本知识可以先google一下,不是很难理解 线段树功能:update:单点增减 query:区间求和 #include <bits/stdc++.h> #define lson ...
- Color the ball 线段树 区间更新但点查询
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #inclu ...
- hdu 1556 Color the ball (树状数组)
Color the ballTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
随机推荐
- ObservableCollection 类
假设您正在创建 Windows 窗体应用程序,并且已将 DataGridView 控件绑定到标准 List(Of Customer) 数据结构.您希望能够使网格中的项目与基础数据源中的值保持同步.也就 ...
- vs报错“以下文件中的行尾不一致,是否将行尾标准化”
vs报错"以下文件中的行尾不一致,是否将行尾标准化" 分析: 通过读取源文件,发现换行都使用的是"\n" Windows和Unix不同的标准引起的...即& ...
- python---异步IO(asyncio)协程
简单了解 在py3中内置了asyncio模块.其编程模型就是一个消息循环. 模块查看: from .base_events import * from .coroutines import * #协程 ...
- ListView - SimpleAdapter 行间颜色交替(转)
一.概述 通过扩展SimpleAdapter,来改变显示外观.因为要每行的显示颜色,首先要获得每行的View实例,然后调用setBackgroundColor函数设置. 二.实例 [效果] [代码片段 ...
- VMware 12安装虚拟机Mac OS X 10.10使用小技巧(虚拟机Mac OS X 10.10时间设置,虚拟机Mac OS X 10.10通过代理上网,Mac OS X 10.10虚拟机优化,VMware虚拟机相互复制)
1:修改Mac OS 系统时间 2:Mac OS系统 通过代理上网 VMware 12安装Mac OS X 10.10虚拟机优化心得 虚拟显卡硬伤,所以必须要优化下才能用,优化的原则就是能精简的精简, ...
- z-index 不起作用
1.第一种情况(z-index无论设置多高都不起作用情况): 这种情况发生的条件有三个: 1.父标签 position属性为relative: 2.问题标签无position属性(不包括static) ...
- Python3 PyPAML 模块(配置文件的操作)
YAML 是专门用来写配置文件的语言,非常简洁和强大 它的基本语法规则如下: 1.大小写敏感 2.使用缩进表示层级关系 3.缩进时不允许使用Tab键,只允许使用空格. 4.缩进的空格数目不重要,只要相 ...
- Django rest framework 的认证流程(源码分析)
一.基本流程举例: urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^users/', views.HostView.as_view() ...
- [New learn]AutoLayout调查基于code
代码https://github.com/xufeng79x/TestAutolayout-code2 0.插在前面 必须关闭view的自动缩放掩码,自动缩放掩码是autolayout出现之前系统管理 ...
- IE7下面iframe滚动条无法用鼠标轮滚 其他浏览器可以
1.让 IFRAME 隐藏滚动条,通常的做法就是在嵌入 IFRAME 的页面的 CSS 中指定以下规则: html, body {overflow: hidden} 2.如果只是想隐藏横向滚 ...