Counting Stars
Counting Stars
题目链接:http://acm.xidian.edu.cn/problem.php?id=1177
离线+树状数组
一眼扫过去:平面区间求和,1e6的数据范围,这要hash+二维树状数组吧?这么短时间我肯定调不出来,果断弃...
结束后有人说一维树状数组可以做,ヾ(。`Д´。)离线啊没想到。
然后就成了水题...(坐标要++,因为是从零开始的)
感悟:离线算法在某种情况下可以降低复杂度的维度。
代码如下:
#include<cstdio>
#include<algorithm>
#include<cstring>
#define met(a,b) memset(a,b,sizeof(a))
#define N 200005
#define M 1000001
using namespace std;
struct nod{
int x,y,index,type,v;
}a[N];
int tree[M];
bool cmp(nod a,nod b){
if(a.y==b.y)return a.x<b.x;
else return a.y<b.y;
}
bool recover(nod a,nod b){
if(a.type==b.type)return a.index<b.index;
else return a.type<b.type;
}
int n,m,x,y,k;
void init(){
met(a,);
met(tree,);
}
int lowbit(int x){
return x&(-x);
}
void add(int x){
for(int i=x;i<M;i+=lowbit(i))
tree[i]++;
}
int query(int x){
int sum=;
for(int i=x;i>;i-=lowbit(i))
sum+=tree[i];
return sum;
}
int main(void){
for(int times=;~scanf("%d%d",&n,&m);++times){
init();
for(k=;k<n;++k){
scanf("%d%d",&x,&y);
x++,y++;
a[k].x=x;
a[k].y=y;
a[k].type=;
}
for(;k<n+m;++k){
scanf("%d%d",&x,&y);
x++,y++;
a[k].x=x;
a[k].y=y;
a[k].type=;
a[k].index=k-n;
}
sort(a,a+k,cmp);
printf("Case #%d:\n",times);
for(int i=;i<k;++i){
if(a[i].type==)add(a[i].x);
else a[i].v=query(a[i].x);
}
sort(a,a+k,recover);
for(int i=;i<m;++i)
printf("%d\n",a[i].v);
}
}
Counting Stars的更多相关文章
- XidianOJ 1177 Counting Stars
题目描述 "But baby, I've been, I've been praying hard, Said, no more counting dollars We'll ...
- HDU 6184 Counting Stars
Problem Description Little A is an astronomy lover, and he has found that the sky was so beautiful!S ...
- 【刷题】HDU 6184 Counting Stars
Problem Description Little A is an astronomy lover, and he has found that the sky was so beautiful! ...
- [hdu 6184 Counting Stars(三元环计数)
hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...
- HDU 6184 Counting Stars 经典三元环计数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6184 题意: n个点m条边的无向图,问有多少个A-structure 其中A-structure满足V ...
- HDU6184【Counting Stars】(三元环计数)
题面 传送门 给出一张无向图,求 \(4\) 个点构成两个有公共边的三元环的方案数. 题解 orz余奶奶,orz zzk 首先,如果我们知道经过每条边的三元环个数\(cnt_i\),那么答案就是\(\ ...
- hdu6184 Counting Stars 【三元环计数】
题目链接 hdu6184 题解 题意是让我们找出所有的这样的图形: 我们只需要求出每条边分别在多少个三元环中,记为\(x\),再然后以该点为中心的图形数就是\({x \choose 2}\) 所以我们 ...
- 全国高校网安联赛Web专场~WriteUp
1.Sign 题目:Good Luck!flag{X-nuca@GoodLuck!} Flag直接写在题目上了,flag{X-nuca@GoodLuck!} 2.BaseCoding 提示:这是编码不 ...
- Python 新浪微博中提取最常见转载的微博转载了几次,username,内容
CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-4 @author: guaguastd @name: fi ...
随机推荐
- C#Redis字符串
上周六通宵打牌周日白天只睡3小时累成狗,从今天起以后不能玩太大的了,小赌怡情大赌伤身,和同事朋友有空玩玩还是好的.今天公司外面马路上有人挂灯笼时死了一个人,哎,快过年了悲剧又发生了,真是生命是脆弱的. ...
- 校门外的树 OpenJudge 1.6.06
06:校门外的树 总时间限制: 1000ms 内存限制: 65536kB 描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0 ...
- cookie解决 未登录加入购物车 第一次访问弹出新手引导页面
浏览器携带cookie到服务器, 点击加入购物车-->后台检查-->是否登录(有没有sessionid) 没有登录--->secookie()返回给浏览器,把传递过来的商品id, 属 ...
- jndi 与 jdbc
现在开发中经常用到数据库的两种配置1 jdbc2 jndi 一般开发环境都会使用jdbc环境,自己弄配置方便.但是测试和生产环境一般都使用jndi方式.原因有:1 使用jndi方式配置,数据库的 ...
- dirty cow exp
公司搞底层的改了一下,说做到了几个不死机 /* * (un)comment correct payload first (x86 or x64)! * * $ gcc cowroot.c -o cow ...
- OBIEE接受外部参数
样例: http://192.168.0.99/analytics/saw.dll?Go&Path=/shared/goxiangyibiaopan/SBDW_GSYDL_ZZT&Ac ...
- CODE[VS]-蛇形矩阵-模拟-天梯白银
题目描述 Description 小明玩一个数字游戏,取个n行n列数字矩阵(其中n为不超过100的奇数),数字的填补方法为:在矩阵中心从1开始以逆时针方向绕行,逐圈扩大,直到n行n列填满数字,请输出该 ...
- table中td内容过长 省略号显示
首先设置 css样式: table { table-layout: fixed;} HTML中的table代码: <tr> <th class="col-md-1" ...
- 使用curl来调试你的应用
我们在客户端开发过程中总免不了和后端进行api对接,有时候需要对返回的数据格式进行调试,有时候每次运行客户端来发送请求,这个未免效率太低,这里就来介绍一个好用的工具--curl. curl curl是 ...
- 单向链表仿LinkedList
public class ChainTable { private Node firstNode;//第一个节点 private Node lastNode;//最后一个节点 private int ...