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

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

就是,它同时被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. Xamarin Android 记事本(三)删改

    这篇我就不做太多的说明了,数据操作之前也都举过例子了,这里就直接贴出删除和修改的代码. public override bool OnOptionsItemSelected(IMenuItem ite ...

  2. 记一次OGG数据写入HBase的丢失数据原因分析

    一.现象二.原因排查2.1 SparkStreaming程序排查2.2 Kafka数据验证2.3 查看OGG源码2.3.1 生成Kafka消息类2.3.2 Kafka配置类2.3.3 Kafka 消息 ...

  3. CarbonData

    CarbonData http://carbondata.apache.org/ Apache顶级项目CarbonData应用实践与2.0新技术规划介绍_搜狐科技_搜狐网 https://www.so ...

  4. Scaling with Microservices and Vertical Decomposition

    Scaling with Microservices and Vertical Decomposition – dev.otto.de https://dev.otto.de/2014/07/29/s ...

  5. $.ajax 使用详解

    Jquery在异步提交方面封装的很好,直接用AJAX非常麻烦,Jquery大大简化了我们的操作. $.post.$.get是一些简单的方法,如果要处理复杂的逻辑,还是需要用到jQuery.ajax() ...

  6. poj 3585 Accumulation Degree(二次扫描和换根法)

    Accumulation Degree 大致题意:有一棵流量树,它的每一条边都有一个正流量,树上所有度数为一的节点都是出口,相应的树上每一个节点都有一个权值,它表示从这个节点向其他出口可以输送的最大总 ...

  7. 通达OA二次开发 工作流表单中关联查询另外一个工作流方法(源代码)

    一个工作流表单中,怎样方便的查询相关的工作流表单内容.重复打开各个菜单必定须要造成多次点击浪费时间,切换也会带来思路的中断.这里通过js代码的方式把这个问题进行了解决. <style>&l ...

  8. var和let的区别(详解)

    1. 作用域 通过var定义的变量,作用域是整个封闭函数,是全域的 . 通过let定义的变量,作用域是在块级或是子块中. function varTest() { var x = 1; if (tru ...

  9. 20170228 METHOD handle_data_changed-

    CALL METHOD er_data_changed->add_protocol_entry   METHOD handle_data_changed. DATA: ls_modi TYPE  ...

  10. swift的String处理

    import UIKit import CoreText class ViewController: UIViewController { override func viewDidLoad() { ...