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 ...
随机推荐
- find unique values in an array
Problem: given an array that contains duplicates (except one value), find the one value that does no ...
- weblogic11g 配置数据源
配置连接数据源步骤详解: 服务器:Weblogic11g,使用JNDI配置 步骤一: 输入http://localhost:7001/console/,登录控制台: 步骤二:按下图要求配置后,进入“下 ...
- RichTextEditor 文本编辑
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- html 页面视图中的资源文件(css/js/image)的路径问题。
说到html 页面视图中的资源文件的路径引用问题,这个问题以前一直没去弄明白.今天,我将公司新开发的一个项目完全移植到我本地搭建的php 环境中来,遇到了这个问题,想了一下,然后也不是很困难的就把它给 ...
- idea 注册机生成密钥代码
import java.math.BigInteger; import java.util.Date; import java.util.Random; import java.util.zip.CR ...
- OpenGL ES2.0入门详解
引自:http://blog.csdn.net/wangyuchun_799/article/details/7736928 1.决定你要支持的OpenGL ES的版本.目前,OpenGL ES包含 ...
- LightOJ 1341 Aladdin and the Flying Carpet 算数基本定理
题目大意:给出面积n,和最短边m,求能形成的矩形的个数(不能为正方形). 题目思路:根据算数基本定理有: 1.每个数n都能被分解为:n=p1^a1*p2^a2*^p3^a3……pn^an(p为素数); ...
- How to write a probeContentType() and Usage?
Files.probeContentType() is an instance of FileTypeDetector class's abstract method String FileTypeD ...
- postgresql 在linux上的源码安装
http://my.oschina.net/hippora/blog/375292 下载源码并解压 [root@fnddb ~]# wget https://ftp.postgresql.org/pu ...
- Jenkins email-ext邮件通知模板
http://blog.csdn.net/houyefeng/article/details/51344337 示例 以html格式发送送如下内容:邮件内容为项目名称.构建次数.触发原因.构建日志前1 ...