这题如果用二维树状数组,则会直接爆内存。

那么可以运用扫描线的思路。

就是,它同时被x和y限制了,那么可以在查询的时候,确保x先满足了,(把x按小到大排序)

然后就相当于是关于y的一个一维bit了,

注意同一个点它询问两次。

8
2 2
1 1
1 2
1 3
1 4
1 5
2 1
0 1
2
1 1

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int maxn = 1e6 + ;
struct node {
int x, y, id;
bool operator < (const struct node & rhs) const {
if (x != rhs.x) return x < rhs.x;
else return y < rhs.y;
}
}a[maxn];
int c[maxn];
int lowbit(int x) {
return x & (-x);
}
void upDate(int pos, int val) {
while (pos <= maxn - ) {
c[pos] += val;
pos += lowbit(pos);
}
}
int sum(int pos) {
int ans = ;
while (pos > ) {
ans += c[pos];
pos -= lowbit(pos);
}
return ans;
}
int ser[maxn];
int ans[maxn];
int n;
vector<int>want;
void work() {
memset(c, , sizeof c);
// scanf("%d", &n);
for (int i = ; i <= n; ++i) {
scanf("%d%d", &a[i].x, &a[i].y);
a[i].x++;
a[i].y++;
a[i].id = i;
}
sort(a + , a + + n);
// for (int i = 1; i <= n; ++i) {
// printf("%d %d %d\n", a[i].x, a[i].y, a[i].id);
// }
int m;
scanf("%d", &m);
memset(ser, , sizeof ser);
for (int i = ; i <= m; ++i) {
int id;
scanf("%d", &id);
ser[id] = i;
want.push_back(id);
}
for (int i = ; i <= n; ++i) {
if (ser[a[i].id]) {
ans[a[i].id] = sum(a[i].y);
}
upDate(a[i].y, );
}
for (int i = ; i < want.size(); ++i) {
printf("%d\n", ans[want[i]]);
}
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
while (scanf("%d", &n) != EOF) work();
return ;
}

scau 1144 数星星 bit + 扫描线的思想的更多相关文章

  1. SCAU-1144 数星星-HDU-1166-树状数组的应用

    本文借鉴代码提供:https://www.cnblogs.com/geek1116/p/5566709.html树状数组详解:https://www.cnblogs.com/xenny/p/97396 ...

  2. poj 2352 Stars 数星星 详解

    题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...

  3. codev 2147 数星星

    2147 数星星 http://codevs.cn/problem/2147/ 题目描述 Description 小明是一名天文爱好者,他喜欢晚上看星星.这天,他从淘宝上买下来了一个高级望远镜.他十分 ...

  4. 题解西电OJ (Problem 1008 - 数星星)

    题目内容: Description “不要问我太阳有多高 我会告诉你我有多真 不要问我星星有几颗 我会告诉你很多很多” 一天Qinz和wudired在天上数星星,由于星星可以排列成一条直线,他们比赛看 ...

  5. 一本通1536数星星 Stars

    1536:[例 2]数星星 Stars 时间限制: 256 ms         内存限制: 65536 KB [题目描述] 原题来自:Ural 1028 天空中有一些星星,这些星星都在不同的位置,每 ...

  6. codevs 2147 数星星

    2147 数星星 http://codevs.cn/problem/2147/ 题目描述 Description 小明是一名天文爱好者,他喜欢晚上看星星.这天,他从淘宝上买下来了一个高级望远镜.他十分 ...

  7. codevs——2147 数星星

    2147 数星星  时间限制: 3 s  空间限制: 64000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 小明是一名天文爱好者,他喜欢晚上看星星 ...

  8. codevs2147数星星(哈希)

    2147 数星星  时间限制: 3 s  空间限制: 64000 KB  题目等级 : 钻石 Diamond   题目描述 Description 小明是一名天文爱好者,他喜欢晚上看星星.这天,他从淘 ...

  9. 大红数星星 图论 XD网络赛

    问题 A: 大红数星星 时间限制: 3 Sec  内存限制: 128 MB提交: 1066  解决: 67[提交][状态][讨论版] 题目描述 “三角形十分的美丽,相信大家小学就学过三角形具有稳定性, ...

随机推荐

  1. Smoke testing (software)

    Smoke testing (software) - Wikipedia https://en.wikipedia.org/wiki/Smoke_testing_(software) In compu ...

  2. add time to file name

    add time to file name echo 123 > $(date +"%Y%m%d_%H%M%S").now; mv /mnt/mongodb_data/dat ...

  3. 怎样在QML中利用Sprite来做我们须要的动画

    在游戏中动画的设计很中要. 在QML中,它提供了丰富的animation.可是有时我们须要对图像进行变化,就像放电影一样.在今天的这篇文章中,我们将设计一个能够变化图像的动画. 我们能够通过Qt所提供 ...

  4. Windows 7 繁体中文MSDN原版

    Win7 SP1 64位旗舰版繁体版ISO镜像(香港):文件名:hk_windows_7_enterprise_with_sp1_x64_dvd_620688.isoSHA1:82D59B099333 ...

  5. 请问snmp到底是干啥的。

    这个事情分两方面来说:首先是路由器这部分.路由器开启SNMP功能之后,它能够对自己的每个接口上的流量有一个统计,当然统计的不单单只有流量.然后路由器把统计到的内容按一定的格式保存起来.这个格式是大家都 ...

  6. 织梦CMS首页、列表页文章如何调出该文章TAG标签?

    1.如果是dedecms v5.7版本直接使用标签 [field:id function=GetTags(@me)/] 就可以调用出来了.只不过不带连接的. 2.如果需要连接请注释掉include/h ...

  7. emacs环境配置

    Cscope: 首先官网上下载cscope的源码包,解压进入,按照INSTALL的说明: ./configure make make install 但是在make时报如下错误:fatal error ...

  8. MP4V2库与MP4AV库编译

    最近在开发一个将RTP流存储为MP4文件的功能.其中针对MP4文件读写,用到了两个开源的库.其中MP4V2用于数据的读写,MP4AV用于对其中的数据帧进行分析. MP4V2和MP4AV都是开源项目MP ...

  9. sql server2008配置管理工具服务显示远程过程调用失败

    SQL SERVER2008配置管理工具服务显示远程过程调用失败   前两天,装了VS2012后,打开SQL2008配置管理工具,发现SQL服务名称里什么也没有,只有一个提示:(如图) 上网搜了,试了 ...

  10. pl/sql developer中如何导出oracle数据库结构? 参考文章一

    本文作者来自csdn的xieyuooo地址为 : http://bbs.csdn.net/topics/340209135 进入PL/SQL后,使用如下图所示的操作步骤: 然后会弹出一个窗口,在弹出窗 ...