ural1470 UFOs
UFOs
Memory limit: 64 MB
- several new UFOs emerge in a certain sector;
- several UFOs disappear in a certain sector;
- Vasya's boss may ask him how many UFOs there are in a part of space consisting of several sectors.
At the moment when Vasya starts his observations there are no UFOs in the whole space.
Input
- If M is 1, then this number is followed by four integers x (0 ≤ x < N), y (0 ≤ y < N), z (0 ≤ z < N), K (–20000 ≤ K ≤ 20000), which are coordinates of a sector and the change in the number of UFOs in this sector. The number of UFOs in a sector cannot become negative.
- If M is 2, then this number is followed by six integers x1, y1, z1, x2, y2, z2 (0 ≤ x1 ≤ x2 <N, 0 ≤ y1 ≤ y2 < N, 0 ≤ z1 ≤ z2 < N), which mean that Vasya must compute the total number of UFOs in sectors (x, y, z) belonging to the volume: x1 ≤ x ≤ x2, y1 ≤ y ≤ y2, z1 ≤ z ≤z2.
- If M is 3, it means that Vasya is tired and goes to sleep. This entry is always the last one.
The number of entries does not exceed 100002.
Output
Sample
input | output |
---|---|
2 |
0 |
分析:三维树状数组,求和时类似于容斥;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t;
ll a[][][];
void add(int x,int y,int z,int w)
{
for(int i=x;i<=n;i+=(i&(-i)))
for(int j=y;j<=n;j+=(j&(-j)))
for(int k=z;k<=n;k+=(k&(-k)))
a[i][j][k]+=w;
}
ll get(int x,int y,int z)
{
ll ans=;
for(int i=x;i;i-=(i&(-i)))
for(int j=y;j;j-=(j&(-j)))
for(int k=z;k;k-=(k&(-k)))
ans+=a[i][j][k];
return ans;
}
int main()
{
int i,j;
scanf("%d",&n);
while(~scanf("%d",&m)&&m!=)
{
if(m==)
{
int b[];
rep(i,,)scanf("%d",&b[i]);
add(++b[],++b[],++b[],b[]);
}
else
{
int b[];
rep(i,,)scanf("%d",&b[i]),b[i]++;
printf("%lld\n",get(b[],b[],b[])
-get(b[]-,b[],b[])-get(b[],b[]-,b[])-get(b[],b[],b[]-)
+get(b[]-,b[]-,b[])+get(b[],b[]-,b[]-)+get(b[]-,b[],b[]-)
-get(b[]-,b[]-,b[]-));
}
}
//system("Pause");
return ;
}
ural1470 UFOs的更多相关文章
- 1470. UFOs(三维树状数组)
1470 最简单的三维树状数组 #include <iostream> #include<cstdio> #include<cstring> #include< ...
- USACO . Your Ride Is Here
Your Ride Is Here It is a well-known fact that behind every good comet is a UFO. These UFOs often co ...
- UserControl和CustomControl基础【PluraSight】
UserControl UserControl实际上就是ContentControl,xaml里<UserControl></UserControl>tag之间包含的实际就是后 ...
- R简易入门(二)
本文内容来源:https://www.dataquest.io/mission/128/working-with-data-frames 本文摘要:简单介绍一下用R处理数据 原始数据展示(这是一份 ...
- CDH-5.4.3离线安装
使用CM离线安装CDH-5.4.3,如下: cdh5.4.3安装 配置/etc/hosts vim /etc/hosts 192.168.10.1 s1 192.168.10.2 s2 192.168 ...
- (17)Questioning the universe
https://www.ted.com/talks/stephen_hawking_asks_big_questions_about_the_universe/transcript00:13There ...
- Rails 5 Test Prescriptions 第8章 Integration Testing with Capybara and Cucumber
Capybara: A complete reference is available atrubydoc.info. 集成测试就是把局部的程序组合起来测试. 端到端测试是一个特殊的集成测试,覆盖了 ...
- USACO_1.1_Your_Ride_Is_Here_(字符串+水题)
描述 http://train.usaco.org/usacoprob2?a=y0SKxY0Kc2q&S=ride 给出两个由大写字母组成,长度不大于$6$的字符串. 将字符串中的各字母的字典 ...
- 【字符串】Your Ride Is Here
题目描述 It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect ...
随机推荐
- Vim常用命令【转载】
下面基本是vim的基本用法,刚开始学习可能有些不习惯.但贵在坚持,即使不习惯,也要坚持使用,做到不经过思考就能操作,你会发现真的很方便.很多操作可以通过不同的命令达到,我这里只列出常用的. 基础命令 ...
- 缩放系列(三):一个可以手势缩放、拖拽、旋转的layout
弄了一个下午,终于搞出来了,PowerfulLayout 下面是一个功能强大的改造的例子: 可以实现以下需求: 1.两个手指进行缩放布局 2.所有子控件也随着缩放, 3.子控件该有的功能不能丢失(像b ...
- android之DPAD上下左右四个键控制
我们代码的目的很简单,那就是监听上下左右中这几个键的事件触发.直接上代码: dpad.xml <?xml version="1.0" encoding="utf-8 ...
- Bitmap和Drawable浅谈
一.概念区别 Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565.RGB8888.作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低.我们理解为一 ...
- 安装你自己的perl modules
来源: http://www.cnblogs.com/itech/archive/2012/12/17/2822044.html 安装你自己的perl modules.当没有root权限的时候,需要安 ...
- Hibernate写入Oracle Date类型处理
Hibernate写入Oracle数据库时,数据库设计字段为Date类型时,只能保存年月日,不能保存时分秒,如果要保存时分秒,需修改Hibernate.cfg.xml文件 <property n ...
- docker certificates
x509: certificate is valid for mmtrkjy.com, *.mmtrkjy.com, *.mmtrkmc.com, *.mmtrkpd.com, *.mmtrksg.c ...
- 转 : 如何用sys as sysdba权限连接数据库进行EXP/IMP
使用sys as sysdba权限进行EXP/IMP与其它用户稍有不同,详细内容如下(摘自metalink) Applies to: Oracle Server - Enterprise Editio ...
- oracle sqlplus @@用法
本文章已收录于: .embody { padding: 10px 10px 10px; margin: 0 -20px; border-bottom: solid 1px #ededed } .e ...
- 如何查看自己电脑支持OpenGL core版本
1. 起因: 红宝书上的例子在电脑上运行后没有效果,但是怎么也找不到原因,反复对看了书上的源码和代码发现没有任何问题,但是就是没有树上写的效果 2. 思路:查看函数的说明,这里推荐使用docs.gl, ...