【HDOJ】4325 Flowers
树状数组+离散化的题目,一直在思考为什么结果不一样,后来才发现花开了就是开了不会再谢了。
/* 4325 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std; #define MAXN 100005 typedef struct {
int s, t;
} node_t; node_t nodes[MAXN];
int qi[MAXN];
int buf[MAXN*];
int sum[MAXN]; inline int lowbit(int x) {
return -x&x;
} void update(int i, int v, int n) {
while (i <= n) {
sum[i] += v;
i += lowbit(i);
}
} int query(int i) {
int ret = ; while (i) {
ret += sum[i];
i -= lowbit(i);
} return ret;
} int main() {
int t, n, m, l;
int i, j, k, tmp;
int a, b, c; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif scanf("%d", &t);
for (int tt=; tt<=t; ++tt) {
scanf("%d %d", &n, &m);
l = ;
for (i=; i<n; ++i) {
scanf("%d %d", &nodes[i].s, &nodes[i].t);
buf[l++] = nodes[i].s;
buf[l++] = nodes[i].t;
}
for (i=; i<m; ++i) {
scanf("%d", &qi[i]);
buf[l++] = qi[i];
} // discretization
buf[l++] = ;
sort(buf, buf+l);
c = unique(buf, buf+l) - buf; memset(sum, , sizeof(sum));
for (i=; i<n; ++i) {
a = lower_bound(buf, buf+c, nodes[i].s) - buf + ;
b = lower_bound(buf, buf+c, nodes[i].t) - buf + ;
update(a, , c);
update(b+, -, c);
} printf("Case #%d:\n", tt);
for (i=; i<m; ++i) {
j = lower_bound(buf, buf+c, qi[i]) - buf + ;
k = query(j);
printf("%d\n", k);
}
} return ;
}
【HDOJ】4325 Flowers的更多相关文章
- 【HDOJ】4729 An Easy Problem for Elfness
其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...
- 【HDOJ】【3506】Monkey Party
DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...
- 【HDOJ】【3516】Tree Construction
DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...
- 【HDOJ】【3480】Division
DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...
- 【HDOJ】【2829】Lawrence
DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...
- 【HDOJ】【3415】Max Sum of Max-K-sub-sequence
DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...
- 【HDOJ】【3530】Subsequence
DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
- 【HDOJ】【1512】Monkey King
数据结构/可并堆 啊……换换脑子就看了看数据结构……看了一下左偏树和斜堆,鉴于左偏树不像斜堆可能退化就写了个左偏树. 左偏树介绍:http://www.cnblogs.com/crazyac/arti ...
随机推荐
- PyCharm4注册码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 name : newasp == ...
- IDL实现主成分变化(PCA)
IDL只能通过调用envi的二次接口做图像的变换,但是对于普通的数据没有提供函数.根据主成分变换的原理,用IDL写出来了,这样就不用每次再去用matlab的princomp去做了.主成分变化的基本过程 ...
- Android系统移植与驱动开发——第七章——LED驱动
LED驱动的实现原理 编写LED驱动: 测试LED驱动之前需要用USB数据线连接开发板,然后打开电源,成功启动之后,执行build.sh脚本文件编译和安装LED驱动,顺利则会自动连接 如果有多个设备文 ...
- 【分享】w32service table XPsp2
Ord Address fnAddr Symbols-------------------------------- [ 0] BF999280: BF93569A (win32k!Nt ...
- .net框架介绍
.net 一般指 .net Framework框架,是一种平台,一种技术 C# 是一种编程语言,可以开发基于.net平台的应用 Java 既是一种技术,也是一种语言 .net可以开发桌面应用程序 ...
- Xcode7 通过 Single View Application 得到一个 Empty Application 工程
方法: 创建一个 Empty Application 工程 下面还是详细的说一下通过一个 Single View Application 工程得到一个 Empty Application 工程的方法: ...
- <body>标签,网页上显示的内容放在这里
在网页上要展示出来的页面内容一定要放在body标签中.如下图是一个新闻文章的网页. 在浏览器中的显示效果: 示例: <!DOCTYPE HTML> <html> <hea ...
- [!] CocoaPods was not able to update the `master` repo...
输入pod install之后出现: [!] CocoaPods was not able to update the `master` repo. If this is an unexpected ...
- SqlDependency 的使用
1.SqlDependency是什么: SqlDependency 对象表示应用程序和 SQL Server 实例间的查询通知依赖关系.应用程序可以创建一个 SqlDependency 对象并进行注册 ...
- mysql 字符串拼接函数CANCAT()与GROUP_CANCAT()
1.CONCAT() 拼接单行字符串 select concat(‘100’,user_id) from table1; select concat('11','22','33'); 结果 11223 ...