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 ...
随机推荐
- JPG、PNG和GIF图片的基本原理及优化方法
一提到图片,我们就不得不从位图开始说起,位图图像(bitmap),也称为点阵图像或绘制图像,是由称作像素(图片元素)的单个点组成的.这些点可以进行不同的排列和染色以构成一副图片.当放大位图时,可以看见 ...
- ios 视频播放
#import "ViewController.h"@import MediaPlayer; @interface ViewController (){ MPMoviePla ...
- 还在纠结 Flux 或 Relay,或许 Redux 更适合你
重磅消息,Redux 1.0 发布,终于可以放心用于生产环境了! 在这个端应用技术膨胀的时代,每天都有一大堆框架冒出,号称解决了 XYZ 等一系列牛 X 的问题,然后过一段时间就不被提起了.但开发的应 ...
- MySQL SQL优化——分片搜索
DELIMITER $$ DROP PROCEDURE IF EXISTS `test_release`.`Sp_JP_A_NotifyBegin`$$ CREATE DEFINER=`encysys ...
- c语言库函数
#include <stdio.h> #define LENGTH 100 main() { FILE *fd; char str[LENGTH]; fd = fopen("he ...
- event小解
首先是一个小例子: <input type="text" onclick="a(event)"/> function a(event){ con ...
- jave学习1--基础介绍
java 技术主要分为三个部分: jave SE基础知识. 对于各个程序的开发语言都包含的基本数据类型,循环控制,数组,方法等. jave SE的面向对象部分. 所有的面向对象的概念,为最终的接口准备 ...
- Alamofire 框架浅析
下面是 Github 主页上对 Alamofire 的描述 Elegant HTTP Networking in Swift 为什么这次我选择阅读 Alamofire 的源代码而不是 AFNetwor ...
- python 第三方库下载
C:\Python27\Scripts 路径下: easy_install.exe: C:\Python27\Scripts>easy_install.exe pycrypto pip.exe: ...
- 学习笔记——桥接模式Bridge
桥接模式的目的是在设计初,就将实现与接口分离,在以后实现发生变化时,只需要改变传递的实现对象,在保持接口一致的情况,达到实现的变更. 在OperationInterface中就调用实现的方法imp.O ...