Interval

时间限制:2000 ms  |  内存限制:65535 KB
难度:4

描述
There are n(1 <= n <= 100000) intervals [ai, bi] and m(1 <= m <= 100000) queries, -100000 <= ai <= bi <= 100000 are integers.
Each query contains an integer xi(-100000 <= x <= 100000). For each query, you should answer how many intervals convers xi.
输入
The first line of input is the number of test case.
For each test case,
two integers n m on the first line, 
then n lines, each line contains two integers ai, bi;
then m lines, each line contains an integer xi.
输出
m lines, each line an integer, the number of intervals that covers xi.
样例输入
2
3 4
1 3
1 2
2 3
0
1
2
3
1 3
0 0
-1
0
1
样例输出
0
2
3
2
0
1
0
      很久没写树状数组了,正好看到了,就复习一下,本题是树状数组-----插线问点的问题

注意写树状数组时候把区间都扩大到大于0的区间上,不能等于0.否则会一直超时,代码如下:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4
 5 using namespace std;
 6
 7 int num[200005];
 8
 9 int lowbit(int i)
10 {
11     return i & (-i);
12 }
13
14 void update(int i, int add)
15 {
16     while(i <= 200001)
17     {
18         num[i] += add;
19         i += lowbit(i);
20     }
21 }
22
23 int getsum(int x)
24 {
25     int ans = 0;
26     while(x > 0)
27     {
28         ans += num[x];
29         x -= lowbit(x);
30     }
31     return ans;
32 }
33
34 int main()
35 {
36     int T, m, n, s, t, x;
37     scanf("%d", &T);
38     while(T--)
39     {
40         memset(num, 0, sizeof(num));
41         scanf("%d%d", &m, &n);
42         while(m--)
43         {
44             scanf("%d%d", &s, &t);
45             update(s+100001, 1);
46             update(t+100001+1, -1);
47         }
48         while(n--)
49         {
50             scanf("%d", &x);
51             printf("%d\n", getsum(x+100001));
52         }
53     }
54     return 0;
55 }

 

NYOJ-522 Interval相关推荐

  1. NYOJ 30 Gone Fishing JAVA+解析

    Gone Fishing这道题目运用的多次折合成一次这种思想我首次见,我想的一个思路是,每次算一下鱼量和时间代价比,这个代码我没有敲,下面的代码是一位仁兄敲得,我研读了一下,做了一个注释,应该有利于后 ...

  2. 057 Insert Interval 插入区间

    给出一个无重叠的按照区间起始端点排序的区间列表. 在列表中插入一个新的区间,你要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间). 示例 1: 给定区间 [1,3],[6,9],插入并 ...

  3. INTERVAL数据类型-007学习笔记

    http://baggio785.itpub.net/post/31233/286119 INTERVAL数据类型用来存储两个时间戳之间的时间间隔. 可以指定years and months,或者da ...

  4. Python使用matplotlib可视化时间序列数据、并为时间序列曲线添加误差带、使用95%置信区间(Time Series Error Bands with confidence interval

    Python使用matplotlib可视化时间序列数据.并为时间序列曲线添加误差带.使用95%置信区间(Time Series with Error Bands with confidence int ...

  5. pandas使用query函数查询指定日期索引之间对应的dataframe数据行(select rows date index between a certain date interval)

    pandas使用query函数查询指定日期索引之间对应的dataframe数据行(select rows where date index between a certain date interva ...

  6. R语言ggplot2可视化使用geom_ribbon()函数向ggplot2图添加置信度带(Confidence Band、Confidence Interval)

    R语言ggplot2可视化使用geom_ribbon()函数向ggplot2图添加置信度带(Confidence Band.Confidence Interval) 目录

  7. Apache Flink 漫谈系列(12) - Time Interval(Time-windowed) JOIN...

    说什么 JOIN 算子是数据处理的核心算子,前面我们在<Apache Flink 漫谈系列(09) - JOIN 算子>介绍了UnBounded的双流JOIN,在<Apache Fl ...

  8. Manacher算法 , 实例 详解 . NYOJ 最长回文

    51 Nod http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1089 Manacher 算法 定义数组 p[i]表示以i为 ...

  9. Oracle:管理 date类型 interval 动态变化的分区:查询、删除

    -- 创建临时表,目的是获取long类型的:high_value 的值 drop table syscom_tab_partition_temp purge ;create table prm8_us ...

  10. NYOJ 527 AC_mm玩dota

    AC_mm玩dota 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 大家都知道AC_mm比较喜欢玩游戏,特别是擅长war3这款经典游戏.某天AC_mm来到了VS平台上 ...

最新文章

  1. iOS开发网络篇—NSURLConnection基本使用(一)
  2. python3 numpy. ndarray 与 list 互转方法
  3. 牛客OI周赛10-提高组:B-Taeyeon的困惑(值域线段树)
  4. 为什么mysql第一步安装_Mysql安装步骤
  5. 读取当前linux进程内存_(笔记)Linux上的内存分配
  6. Truncated SVD for faster dection
  7. Linux部署安装JDK
  8. Android 系统(66)---Android硬件加速相关问题总结
  9. apex您所在的地区目前不提供此物品_《APEX英雄》入门指南传奇篇-命脉
  10. 骗术 —— 魔高一尺道高一丈
  11. MyBatis_Study_004(动态代理)
  12. 周礼键君:中国福建省建瓯市之《闽郡八音字典》
  13. Japan games Android,Learn Japanese with Games
  14. 案例|山东省中医院基于ZABBIX构建网络设备监控预警平台
  15. 最小二乘法的计算过程
  16. Nodejs日志库winston配置
  17. 华为ensp Cloud连接使用及创建环回适配器网卡
  18. Magic Potion(最大流,跑两遍网络流或者加一个中转点)
  19. windows 7 桌面IE图标不见了
  20. python脚本AttributeError: module 'xxxx' has no attribute 'xxxxx'错误解决办法

热门文章

  1. Sitecore A / B测试
  2. jdk1.8以前不建议使用其自带的Base64来加解密
  3. POJ - 3470 Walls
  4. HttpWebRequest post上传文件
  5. VScode PowerShell运行脚本报错禁止运行脚本解决方式图文
  6. MariaDB 脚本
  7. ironic如何支持部署时按需RAID?
  8. 20172311 2017-2018-2 《程序设计与数据结构》第八周学习总结
  9. 20165320 第九周学习总结
  10. ctsc2009 移民站选址