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 ...
随机推荐
- [ios2] 利用钥匙串,在应用里保存用户密码的方法 【转】
想在应用里保存帐号.密码等信息的话,直接存到 plist 里显然是不负责任的,自己折腾加密既麻烦又不能保证不被反编译破解.实际上苹果 iOS 和 Mac OS X 系统自带了一套敏感信息保存方案:&q ...
- [ios2]OS 6 SDK: 在应用内展示App Store【转】
出于什么样的原因你会希望用户从你的iOS app中进入App Store呢?可能你想用户去App Store 为你的应用评分,也可能你希望用户看到你其他的iOS app.iOS 6引入了SKStore ...
- Struts入门(二) 配置文件的讲解
上一章我们演示了Struts项目的搭建 可以看到里面有几个重要的配置文件 下面我们来说明一下这3个配置文件 1.web.xml 2.strtus.xml 3.struts.properties 1 ...
- Linux下产生随机密码10方法
有特殊符号的: cat /dev/urandom | tr -dc "a-zA-Z0-9_+\~\!\@\#\$\%\^\&\*"| fold -w 16 |head -n ...
- 教你成为全栈工程师(Full Stack Developer) 一-各显神通总结八大类编程语言的区别
为了能在最快的时间里理解更多语言的相同点和不同点,我用大家最熟悉的Hello World来展示一下各个语言的奥妙 请尊重原创,转载请注明来源网站www.shareditor.com以及原始链接地址 ...
- Method Invocation Expressions
15.12.1. Compile-Time Step 1: Determine Class or Interface to Search The first step in processin ...
- Unity中的Mathf类
Mathf.Abs绝对值 计算并返回指定参数 f 绝对值. Mathf.Acos反余弦 static function Acos (f : float) : float 以弧度为单位计算并返回参数 f ...
- Latex—IEEE Latex模板 期刊名带下划线的问题解决
其实期刊名应该是斜体字的,但是有可能默认模板会导致斜体变下划线的问题,解决方法如下 引用包: \usepackage{ulem} %to strike the words 然后再在: \bibliog ...
- android屏幕适配之度量单位、屏幕分类、图标尺寸归类分析
好久没有做android项目UI的适配了,好多基本概念都已经模糊了,于是萌生了将屏幕分辨率.常用单位.常用图标尺寸等信息规整的想法,一下就是通过查询资料,自己验证的一些随笔,如有失误之处,望大家及时予 ...
- c#的as关键字
类型a as 类型b ,把类型a强制变为类型b