(简单) 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 ...
随机推荐
- b端商家赋值权限
- CodeForces 567B Berland National Library hdu-5477 A Sweet Journey
这类题一个操作增加多少,一个操作减少多少,求最少刚开始为多少,在中途不会出现负值,模拟一遍,用一个数记下最大的即可 #include<cstdio> #include<cstring ...
- Jquery的parent和parents(找到某一特定的祖先元素)
关于Jquery的parent和parents parent是指取得一个包含着所有匹配元素的唯一父元素的元素集合.parents则是取得一个包含着所有匹配元素的祖先元素的元素集合(不包含根元素).可以 ...
- AngularJS 基础用法
判断语句: <li ng-repeat=”person in persons”> <span ng-switch on=”person.sex”> <span ng-sw ...
- UVA 10200 Prime Time (打表)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- Oracle Sql优化之范围处理
1.表中字段自关联与分析函数的性能比较,自关联需要扫描表两次,分析函数扫描一次即可 ----自关联 select v1.proj_id,v1.proj_start,v1.proj_end from v ...
- 转:设置Loadrunner负载机临时文件目录
最近在跑稳定性测试 3 X 24小时的时候,发现负载机产生的日志还运行记录等等竟然有100多G! C盘空间不足,但是D盘还有700多G空间呢,怎么让临时文件转移到D盘? 此处分两种情况: 一. 修改本 ...
- cortexm内核 栈的8字节对齐及关键字PRESERVE8
一.什么是栈对齐? 栈的字节对齐,实际是指栈顶指针须是某字节的整数倍.因此下边对系统栈与MSP,任务栈与PSP,栈对齐与SP对齐 这三对概念不做区分.另外下文提到编译器的时候,实际上是对编译器汇编器连 ...
- CodeForces 83B Doctor
二分查找. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #i ...
- hdu_2222_Keywords Search(AC自动机板子)
题目连接:hdu_2222_Keywords Search 存个自己写的AC自动机 #include<cstdio> #include<cstring> #define F(i ...