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的更多相关文章

  1. XidianOJ 1177 Counting Stars

    题目描述 "But baby, I've been, I've been praying hard,     Said, no more counting dollars     We'll ...

  2. HDU 6184 Counting Stars

    Problem Description Little A is an astronomy lover, and he has found that the sky was so beautiful!S ...

  3. 【刷题】HDU 6184 Counting Stars

    Problem Description Little A is an astronomy lover, and he has found that the sky was so beautiful! ...

  4. [hdu 6184 Counting Stars(三元环计数)

    hdu 6184 Counting Stars(三元环计数) 题意: 给一张n个点m条边的无向图,问有多少个\(A-structure\) 其中\(A-structure\)满足\(V=(A,B,C, ...

  5. HDU 6184 Counting Stars 经典三元环计数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6184 题意: n个点m条边的无向图,问有多少个A-structure 其中A-structure满足V ...

  6. HDU6184【Counting Stars】(三元环计数)

    题面 传送门 给出一张无向图,求 \(4\) 个点构成两个有公共边的三元环的方案数. 题解 orz余奶奶,orz zzk 首先,如果我们知道经过每条边的三元环个数\(cnt_i\),那么答案就是\(\ ...

  7. hdu6184 Counting Stars 【三元环计数】

    题目链接 hdu6184 题解 题意是让我们找出所有的这样的图形: 我们只需要求出每条边分别在多少个三元环中,记为\(x\),再然后以该点为中心的图形数就是\({x \choose 2}\) 所以我们 ...

  8. 全国高校网安联赛Web专场~WriteUp

    1.Sign 题目:Good Luck!flag{X-nuca@GoodLuck!} Flag直接写在题目上了,flag{X-nuca@GoodLuck!} 2.BaseCoding 提示:这是编码不 ...

  9. Python 新浪微博中提取最常见转载的微博转载了几次,username,内容

    CODE: #!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-4 @author: guaguastd @name: fi ...

随机推荐

  1. C语言之字符集、ASCII码和sizeof运算符

    一 字符集和ASCII码 结论:字符本质上也是一个整数,每个字符都有唯一一个与之对应的整数, 比如说小写的a对应97,b对应98,c对应99,大写的A对应65,B对应66,C对应67 所以字符对应的那 ...

  2. ssi-uploader上传图片插件,点击选择文件按钮自动提交表单解决办法

    先介绍一下这款插件,然后再谈使用中可能遇到的问题 ssi-uploader是一个JQuery的图片上传插件,界面比较美观 github地址:https://github.com/ssbeefeater ...

  3. Node.js 使用gm处理图像

    现要对之前的文件服务器进行扩展,听网上说gm处理图像来一套一套的.so决定使用该工具去实现文件服务器的图片处理这块.目标有下现在通过参数去获得缩略图http://xxx.xxx.com/image/2 ...

  4. Elasticsearch 5.0 磁盘空间节省策略的认识

    前言:本文是当时QQ群员讨论磁盘空间如何优化,我搜了下类似的文章,结合官方文档做了一些总结 参考文章1 参考文章2 如果你有疑问,可以联系我参与讨论,或者去原文查看. NOTE: 磁盘空间节省问题,是 ...

  5. shell 读取文件

    #!/bin/bash content=`cat test.txt` echo "begin" for i in $content do echo $i done 读取前10行 t ...

  6. sublime & atom 插件

    1. autofilename(sublime) autocomplete-paths (atom): 自动路径 2. autoprefixer: 自动添加前缀  : https://github.c ...

  7. Java学习笔记-Json

    //先导入gson到lib,add build path //2015年5月5日22:02:37 package com.alfredsun.thread; import com.google.gso ...

  8. Long类型比较大小,long型和Long型区别

    今天写代码发现发现本地程序是正常的,但是发送到测试环境就不正常了,本着对数据的怀疑态度链接了测试数据库,调试程序发现,确实是数据问题,然后数据出现在什么地方呢?才发现是在判断用户所属的teamGrou ...

  9. html5的navigator调用手机震动

    navigator.vibrate(s) 或 navigator.webkitVibrate(s),不过该属性只在安卓系统有效.

  10. 【原创】RMQ - ST算法详解

    ST算法: ID数组下标: 1   2   3   4   5   6   7   8   9    ID数组元素: 5   7   3   1   4   8   2   9   8 1.ST算法作 ...