XidianOJ 1177 Counting Stars
题目描述
"But baby, I've been, I've been praying hard,
Said, no more counting dollars
We'll be counting stars"
Grandpa Shaw loves counting stars.
One evening he was sitting in his armchar, trying to figure out this problem.
Consider the sky as a rectangular coordinates, each star has a coordinate (Xi,Yi).
To make it simple, all the stars are in the first quadrant.
Now he want to know how many stars there are in the square formed by (0,0) and (x,y).
(including stars in edges, 4 vertices of the square is (0,0) (x,0) (x,y) (0,y))
There are n stars in the sky, and he raised m questions.
Because grandpa Shaw's eyesight is poor, he ask you for help.
in this image, yellow stars are in the square, blue ones are not.
输入
multiple test cases, please read until EOF.
for each test case:
first line contains two integers n m (0 <= n, m <= 10^5).
following n lines each line contains two integers Xi Yi (0 <= Xi, Yi <= 10^6).
following m lines each line contains two integers x y (0 <= x, y <= 10^6).
输出
for each test case:
first line "Case #t:" t is the number of test case.
following m lines, each line contains one integer, the number of stars in that square.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int n,m;
int c[],ans[]; struct StarNode {
int x,y;
int num;
bool query;
};
struct StarNode star[]; bool cmp(struct StarNode s1,struct StarNode s2){
if (s1.x == s2.x) return s1.y < s2.y;
return s1.x < s2.x;
}
int lowbit(int i) {
return i&-i;
}
void Update(int i,int x){
while (i < ){
c[i] += x;
i += lowbit(i);
}
}
int Sum(int i){
int s = ;
while (i > ) {
s += c[i];
i -= lowbit(i);
}
return s;
} int main(){
int total = ;
while (scanf("%d %d",&n,&m) != EOF){
memset(c,,sizeof(c)); total ++;
int i,j;
for (i=;i<=n;i++){
int xi,yi;
scanf("%d %d",&star[i].x,&star[i].y);
star[i].query = false;
}
for (i=n+;i<=n+m;i++){
scanf("%d %d",&star[i].x,&star[i].y);
star[i].query = true; star[i].num = i - n;
}
sort(star+,star++n+m,cmp);
printf("Case #%d:\n",total);
for (i=;i<=n+m;i++){
if (star[i].query)
ans[star[i].num] = Sum(star[i].y+);
else
Update(star[i].y+,);
}
for (i=;i<=m;i++)
printf("%d\n",ans[i]);
}
return ;
}
XidianOJ 1177 Counting Stars的更多相关文章
- Counting Stars
Counting Stars 题目链接:http://acm.xidian.edu.cn/problem.php?id=1177 离线+一维树状数组 一眼扫过去:平面区间求和,1e6的数据范围,这要h ...
- 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 ...
随机推荐
- [转]http://lua-users.org/wiki/LpegTutorial
Simple Matching LPeg is a powerful notation for matching text data, which is more capable than Lua s ...
- ecshop安装常见问题及解决办法
一,Ecshop首页出现报错:Only variables should be passed by referen 最近想安装一个ECSHOP商城上去,老是报错,出现下面这就话: Strict Sta ...
- PHP7在linux下的安装步骤
安装mcrypt: yum install -y php-mcrypt libmcrypt libmcrypt-devel 升级bison: cd /var/soft/ wget http://ftp ...
- C++ Primer : 第十三章 : 拷贝控制之拷贝控制和资源管理
定义行为像值的类 行为像值的类,例如标准库容器和std::string这样的类一样,类似这样的类我们可以简单的实现一个这样的类HasPtr. 在实现之前,我们需要: 定义一个拷贝构造函数,完成stri ...
- 数据获取以及处理系统 --- 功能规格说明书V2.0
产品规格说明书: 版本号: V2.0 版本说明: Version 1.0 简单得需求分析以及构思,初稿形成 Version 2.0 细化beta阶段设计,增加典型用户尝尽以及功能罗列 1. 引言 1. ...
- UVa 10815 安迪的第一个字典
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 深入理解AOP
引子: AOP(面向方面编程:Aspect Oriented Programing)和IoC一样是Spring容器的内核,声明式事务的功能在此基础上开花结果.但是AOP和OOP差别较大,要很好地理解这 ...
- Apache配置代理服务器的方法(1)
众所周知Apache是目前最优秀的HTTP服务器.实际上它不仅能当作服务器使用,也能够被用来架设代理服务器.本文就如何使用Apache架设HTTP代理服务器进行说明. 本文将基于Win32版的Apac ...
- 利用pt-deadlock-logger监控死锁
Percona提供的percona-toolkit提供很多实用功能,这里着重介绍如何监控死锁. pt-deadlock-logger基本用法 Usage: pt-deadlock-logger [OP ...
- SQL Server DBA日常查询视图_数据库性能视图
1.获取有关按平均CPU 时间排在最前面的五个查询的信息 total_worker_time/execution_count AS [Avg CPU Time], ), ((CASE qs.state ...