记录编号 118074 评测结果 AAAAAAAAAAAAAAAA
题目名称 数列操作A 最终得分 100
用户昵称 GravatarHouJikan 是否通过 通过
代码语言 C++ 运行时间 0.290 s
提交时间 2014-09-03 21:00:44 内存使用 1.73 MiB
显示代码纯文本
#include <iostream>
#include <cstring>
#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=100000;
LL sum[2*MAXN+1000];
LL k,v;
int n;
//==============function declaration============
void add();//sum[k]+=v;
int lowbit(int x)
{
  return x&-x;
}
LL query(int x);
//==============main code=======================
int main()
{  
  string FileName="shulie";//程序名 
  string FloderName="COGS";//文件夹名 
  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    
  scanf("%d",&n);
  memset(sum,0,sizeof(sum));
  for(k=1;k<=n;k++)
  {
    scanf("%d",&v);
    add();
  }
  int q;
  char cmd[10];
  int s,e;
  scanf("%d",&q);
  For(i,1,q)
  {
    scanf(" %s",cmd);
    if (cmd[0]=='S')
    {
      scanf("%d%d",&s,&e);
      LL a=query(e);
      LL b=query(s-1);
      printf("%lld\n",a-b);
    }
    else if (cmd[0]=='A')
    {
      scanf("%lld%lld",&k,&v);
      add();
    }
  }
#ifdef DEBUG  
  clock_t End_Time=clock();
  cout<<endl<<endl<<"Time Used: "<<double(End_Time-Start_Time)/CLOCKS_PER_SEC<<endl;
#endif    
  return 0;
}
//================fuction code====================
void add()
{
  int x=k;
  while (x<=n)
  {
    sum[x]+=v;
    x+=lowbit(x);
  }
  return ;
}
LL query(int x)
{
  LL res=0;
  while (x>0)
  {
    res+=sum[x];
    x-=lowbit(x);
  }
  return res;
}