2014多校2(1002)hdu4872

ZCC Loves COT

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 160    Accepted Submission(s): 43


Problem Description
After solves all problem of the series COT(count on a tree), ZCC feels bored and came up with a new COT problem, where letter T stands of Tetrahedron.
In this problem, Tetrahedron is define as a set of point:
T(n) = {(x, y, z) | 1≤z≤y≤x≤n}
Imagine T(n) is divided into n layers, the k-th layer contains k rows, of which the l-th row contains l points.
Moreover, we define sub-Tetrahedron a set of point, too:
sT(x, y, z, a) = {(x+i, y+j, z+k) | 0≤k≤j≤i<a}
First of all, you are given a Tetrahedron T(N), every point of T(N) has a value of 0.
Then, you should deal with M operation (Mxi, Myi, Mzi, Mai), means you should add 1 to every point’s value if it belongs to sT(Mxi, Myi, Mzi, Mai).
Then, you should deal with Q queries (Qxi, Qyi, Qzi, Qai), you should output the sum of values of points in sT(Qxi, Qyi, Qzi, Qai).
 

Input
First line: three positive integer N, M, Q.(N≤100, M≤100000, Q≤100000)
Then followed M lines, each line contains four integers Mxi, Myi, Mzi, Mai, which describe an operation.
Then followed Q lines, each line contains four integers Qxi, Qyi, Qzi, Qai, which describe a query.
 

Output
For every query, output a line with one integer, the answer to the query.
 

Sample Input
  
  
2 1 2 1 1 1 2 1 1 1 2 2 1 1 1
 

Sample Output
  
  
4 1
Hint

It is guaranteed, for every sT(x, y, z, a): 1≤z≤y≤x≤x+a-1≤N.

感谢LC大神提供的题解:http://blog.csdn.net/accelerator_916852/article/details/38133849

#include 
       
       
        
        
#include 
        
        
         
         
#include 
         
         
          
          
#include 
          
          
           
           
using namespace std;
#define maxn 105
#define FOR(i,a,b) for(int i=a;i<=b;++i)
typedef __int64  LL;
int n,m,q;

LL flag1z[maxn][maxn][maxn];
LL flag1f[maxn][maxn][maxn];
LL flag2z[maxn][maxn][maxn];
LL flag2f[maxn][maxn][maxn];

LL dpz[maxn][maxn][maxn];
LL dpf[maxn][maxn][maxn];
LL ans[maxn][maxn][maxn];

LL si[maxn][maxn][maxn];
LL yoz[maxn][maxn][maxn];
LL rec[maxn][maxn][maxn];
LL tri[maxn][maxn][maxn];

LL d[maxn][maxn][maxn];

void init()
{
    memset(flag1z,0,sizeof(flag1z));
    memset(flag1f,0,sizeof(flag1f));
    memset(flag2z,0,sizeof(flag2z));
    memset(flag2f,0,sizeof(flag2f));
}

void solve1(int x,int y,int z,int a)
{
    int i,j,k;

    flag1z[x][y][z]++;
    flag1z[x+a][y+a][z+a]--;

    flag2z[x][y+1][z]++;
    flag2z[x+a][y+a+1][z+a]--;

    flag1f[x+a][y][z]++;
    flag1f[x+a][y+a][z+a]--;

    flag2f[x+a][y+a+1][z]++;
    flag2f[x+a][y+a+1][z+a]--;
}

void solve2()
{
    int i,j,k;

    FOR(i,1,n) FOR(j,1,n) FOR(k,1,n){
        flag1z[i][j][k]+=flag1z[i-1][j-1][k-1];
        flag2z[i][j][k]+=flag2z[i-1][j-1][k-1];
        flag1f[i][j][k]+=flag1f[i][j-1][k-1];
        flag2f[i][j][k]+=flag2f[i][j][k-1];
        }

    FOR(i,1,n) FOR(j,1,n) FOR(k,1,n){
        dpz[i][j][k]=dpz[i-1][j][k]+flag1z[i][j][k]-flag1f[i][j][k];
        dpf[i][j][k]=dpf[i-1][j-1][k]+flag2z[i][j][k]-flag2f[i][j][k];
        ans[i][j][k]=ans[i][j-1][k]+dpz[i][j][k]-dpf[i][j][k];
        }

    FOR(i,1,n) FOR(j,1,n) FOR(k,1,n){
                d[i][j][k]=d[i][j][k-1]+ans[i][j][k];
                yoz[i][j][k]=yoz[i][j-1][k-1]+d[i][j][k];
                si[i][j][k]=si[i-1][j-1][k-1]+yoz[i][j][k];
                rec[i][j][k]=rec[i][j-1][k]+d[i][j][k];
                tri[i][j][k]=tri[i-1][j-1][k]+rec[i][j][k];
        }

    FOR(i,1,n) FOR(j,1,n) FOR(k,1,n){
                yoz[i][j][k]+=yoz[i-1][j][k];
                rec[i][j][k]+=rec[i-1][j][k];
        }
}

LL solve3(int x,int y,int z,int a)
{
    return si[x+a-1][y+a-1][z+a-1]-si[x-1][y-1][z-1]-(yoz[x+a-1][y-1][z-1]-yoz[x-1][y-1][z-1])-(tri[x+a-1][y+a-1][z-1]-(rec[x+a-1][y-1][z-1]-rec[x-1][y-1][z-1])-tri[x-1][y-1][z-1]);
}

int main()
{
    int i,j,k;
    int x,y,z,a;
    while(scanf("%d%d%d",&n,&m,&q)!=EOF)
    {
        for(i=0;i
           
           
          
          
         
         
        
        
       
       

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值