记录编号 |
117266 |
评测结果 |
AAAAAAAAAA |
题目名称 |
数列操作C |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.496 s |
提交时间 |
2014-08-29 09:37:52 |
内存使用 |
7.94 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=================
LL sumv[500000];
LL addv[500000];
#define y1 y11
int y1,y2;
LL v;
//==============function declaration============
void add(int o,int l,int r);
LL query(int o,int l,int r,LL adds);
void maintain(int o,int l,int r);
//==============main code=======================
int main()
{
string FileName="shuliec";//程序名
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
int n,q;
scanf("%d",&n);
memset(sumv,0,sizeof(sumv));
memset(addv,0,sizeof(addv));
For(i,1,n)
{
y1=y2=i;
scanf("%lld",&v);
add(1,1,n);
}
scanf("%d",&q);
char cmd[10];
For(i,1,q)
{
scanf(" %s %d %d",cmd,&y1,&y2);
if (cmd[0]=='S')
printf("%lld\n",query(1,1,n,0));
else if(cmd[0]=='A')
{
scanf("%lld",&v);
add(1,1,n);
}
else
{
printf("Init Error!");
return 0;
}
}
#ifdef DEBUG
clock_t End_Time=clock();
printf("\n\nTime Used: %.3lf\n",End_Time-Start_Time);
#endif
return 0;
}
//================fuction code====================
void maintain(int o,int l,int r)
{
int lc=o*2;
int rc=o*2+1;
if (l!=r)
sumv[o]=sumv[lc]+sumv[rc]+addv[o]*(r-l+1);
return;
}
void add(int o,int l,int r)
{
int lc=o*2;
int rc=o*2+1;
int m=(l+r)/2;
if (y1<=l&&r<=y2)
{
addv[o]+=v;
sumv[o]+=(r-l+1)*v;
return;
}
if (m>=y1)
add(lc,l,m);
if (m<y2)
add(rc,m+1,r);
maintain(o,l,r);
}
LL query(int o,int l,int r,LL adds)
{
int lc=o*2;
int rc=o*2+1;
int m=(l+r)/2;
if (y1<=l&&r<=y2)
return sumv[o]+(r-l+1)*adds;
LL res=0;
if (m>=y1)
{
res+=query(lc,l,m,adds+addv[o]);
}
if (m<y2)
{
res+=query(rc,m+1,r,adds+addv[o]);
}
return res;
}