(简单) POJ 2352 Stars,Treap。
Description

For example, look at the map shown on the figure above. Level of the star number 5 is equal to 3 (it's formed by three stars with a numbers 1, 2 and 4). And the levels of the stars numbered by 2 and 4 are 1. At this map there are only one star of the level 0, two stars of the level 1, one star of the level 2, and one star of the level 3.
You are to write a program that will count the amounts of the stars of each level on a given map.
// ━━━━━━神兽出没━━━━━━
// ┏┓ ┏┓
// ┏┛┻━━━━━━━┛┻┓
// ┃ ┃
// ┃ ━ ┃
// ████━████ ┃
// ┃ ┃
// ┃ ┻ ┃
// ┃ ┃
// ┗━┓ ┏━┛
// ┃ ┃
// ┃ ┃
// ┃ ┗━━━┓
// ┃ ┣┓
// ┃ ┏┛
// ┗┓┓┏━━━━━┳┓┏┛
// ┃┫┫ ┃┫┫
// ┗┻┛ ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━ // Author : WhyWhy
// Created Time : 2015年07月17日 星期五 14时44分13秒
// File Name : 1195.cpp #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h> using namespace std; const int MaxN=; int C[MaxN][MaxN];
int N; inline int lowbit(int x)
{
return x&(-x);
} void add(int x,int y,int d)
{
int t; while(x<=N)
{
t=y; while(t<=N)
{
C[x][t]+=d;
t+=lowbit(t);
} x+=lowbit(x);
}
} int query(int x,int y)
{
int ret=;
int t; while(x>)
{
t=y; while(t>)
{
ret+=C[x][t];
t-=lowbit(t);
} x-=lowbit(x);
} return ret;
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout); int a,b,c,d,e; while()
{
scanf("%d",&a); if(a==)
{
scanf("%d %d %d",&b,&c,&d);
add(b+,c+,d);
}
else if(a==)
{
scanf("%d %d %d %d",&b,&c,&d,&e);
printf("%d\n",query(d+,e+)-query(d+,c)-query(b,e+)+query(b,c));
}
else if(a==)
{
scanf("%d",&N);
memset(C,,sizeof(C));
}
else
break;
} return ;
}
(简单) POJ 2352 Stars,Treap。的更多相关文章
- poj 2352 Stars 数星星 详解
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时 ...
- POJ 2352 Stars(线段树)
题目地址:id=2352">POJ 2352 今天的周赛被虐了. . TAT..线段树太渣了..得好好补补了(尽管是从昨天才開始学的..不能算补...) 这题还是非常easy的..维护 ...
- POJ 2352 Stars(树状数组)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 30496 Accepted: 13316 Descripti ...
- 【树状数组】POJ 2352 Stars
/** * @author johnsondu * @time 2015-8-22 * @type Binary Index Tree * ignore the coordinate of y and ...
- hdu 1541/poj 2352:Stars(树状数组,经典题)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- POJ 2352 Stars(HDU 1541 Stars)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 41521 Accepted: 18100 Descripti ...
- [POJ] 2352 Stars [线段树区间求和]
Stars Description Astronomers often examine star maps where stars are represented by points on a pla ...
- POJ 2352 Stars(树状数组)题解
Language:Default Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52268 Accepted: 22 ...
- POJ 2352 stars (树状数组入门经典!!!)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 54352 Accepted: 23386 Descripti ...
随机推荐
- 关于iOS socket都在这里了
socket(套接字)是通信的基石,是支持TCP/IP协议的网络通信的基本操作单元,包含进行网络通信必须的五种信息:连接使用的协议,本地主机的IP地址,本地进程的协议端口,远地主机的IP地址,远地进程 ...
- 转 : ANT 调用sqlplus 客户端
Jenkins安装与配置 (版本控制) 1 用ant脚本执行sql语句现在我需要写一个ant脚本来实现项目安装,情况是这样的,客户现在运行的版本可能是2.0,安装目录里可能有REL_1_0,REL_ ...
- Dockerfile编写语法
docker镜像本质上就是一个个基础镜像的堆叠,为了做出我们想要的镜像,我们需要考虑最终镜像所需的所有基础环境,然后一层层堆叠.也就是不断以基础镜像搭建上层镜像. 先看例子: # Version: # ...
- MySQ安装
1.去官网下载安装包 .http://www.mysql.com/downloads/ 2.安装过程中会出现下面的提示:记得保存你的MySQL的初始的默认密码.如果没有注意,那么恢复起来有点麻烦,后续 ...
- div.2/Bellovin<最长上升子序列>
题意: 序列arr[i--n];输出以a[i]为结尾的最长上升子序列.1<=n<=100000; 思路: O(n*log(n)),求最长上升子序列. #include<cstdio& ...
- jQuery checkbox 全选
jQuery 1.6版本以后 if($("#id").attr("checked")) 不能返回 ture 和 false 高版本中jQuery 提供prop ...
- Java类锁和对象锁实践(good)
一.前言 之前对类锁和对象锁是否是互斥的不是太确定,因此决定编写相关的程序进行实践一下.编写前对相关定义约定约定如下: 1. 类锁:在代码中的方法上加了static和synchronized的锁,或者 ...
- linux服务器性能状态查看
vmstat结果内容的解释 Vmstat procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu---- ...
- hdu_1007_Quoit Design(最近点对)
题目连接:hdu_1007_Quoit Design 题意: 给你平面上的一些点,让你找出这些点的最近点对的距离 题解: 采用分治,达到O(nlognlogn)的时间复杂度就能艹过去了 #includ ...
- 用DIV+CSS做网页里要设置body和*规定内容
body{}表示是对body标签的设置,就是<html><head></head><body></body></html> 里面 ...