记录编号 126579 评测结果 AAAAAAAAAA
题目名称 [IOI 2001] 移动电话 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.176 s
提交时间 2014-10-13 20:06:31 内存使用 4.07 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint; 
const int INF=0x7ffffff;
//==============struct declaration==============

//==============var declaration=================
const int MAXN=1050;
int bit[MAXN][MAXN],n,q,cmd;
//==============function declaration============
int lowbit(int x){return x&-x;}
void inc1(int A,int B,int X);
void inc2(int *S,int x,int v);
int query1(int x1,int x2);
int query2(int *S,int x);
//==============main code=======================
int main()
{  
  string FileName="mobilephones";//程序名 
  //string FloderName="";//文件夹名 
  freopen((FileName+".in").c_str(),"r",stdin);
  freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG  
  //system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
  clock_t Start_Time=clock();
#endif    
  while (scanf("%d",&cmd)&&cmd!=3){
    if (cmd==0)
      scanf("%d",&n);
    else
    if (cmd==1){
      int A,B,X;
      scanf("%d%d%d",&A,&B,&X);A++;B++;
      inc1(A,B,X);
    }
    else if (cmd==2){
      int L,B,R,T;
      scanf("%d%d%d%d",&L,&B,&R,&T);L++;B++;R++;T++;
      int A=query1(L-1,B-1);
      int B1=query1(R,T);
      int C=query1(L-1,T);
      int D=query1(R,B-1);
      printf("%d\n",B1-C-D+A);
    }
  }
#ifdef DEBUG  
  clock_t End_Time=clock();
  printf("\n\nTime Used: %.4lf Ms\n",double(End_Time-Start_Time)/CLOCKS_PER_SEC);
#endif    
  return 0;
}
//================fuction code====================
void inc1(int A,int B,int X)
{
  while (A<=n){
    inc2(bit[A],B,X);
    A+=lowbit(A);
  }
}
void inc2(int *S,int x,int v)
{
  while (x<=n){
    S[x]+=v;
    x+=lowbit(x);
  }
}
int query1(int x1,int x2)
{
   int res=0;
   while (x1>0){
     res+=query2(bit[x1],x2);
     x1-=lowbit(x1);
   }
   return res;
}
int query2(int *S,int x)
{
  int res=0;
  while (x>0){
    res+=S[x];
    x-=lowbit(x);
  }
  return res;
}