| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一发wa 全改longlong就a了#include <iostream> #include<string> #include<cstring> #include<vector> #include<set> #include<stack> #include<queue> #include<list> #include<cmath> #include<algorithm> #include<cstdio> #include<cstdlib> #include<fstream> #include<map> #include<iomanip> using namespace std; #define eps 1e-8 #define INF 0x3f3f3f #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; long long sum[100000<<2]; long long add[100000<<2]; void pushdown(int l,int r,int rt) { if(add[rt]) { int m=(l+r)>>1; add[rt<<1]+=add[rt]; add[rt<<1|1]+=add[rt]; sum[rt<<1]+=(m-l+1)*add[rt]; sum[rt<<1|1]+=(r-m)*add[rt]; add[rt]=0; } } void pushup(int rt) { sum[rt]=sum[rt<<1]+sum[rt<<1|1]; } void build(int l,int r,int rt) { // cout<<"区间"<<rt<<"的左右分别是"<<l<<" "<<r<<endl; add[rt]=0; sum[rt]=0; if(l==r) { int c; scanf("%I64d",&sum[rt]); return ; } int m=(l+r)>>1; build(lson); build(rson); pushup(rt); } void update(int L,int R,long long c,int l,int r,int rt) { if(L<=l&&R>=r) { sum[rt]+=(r-l+1)*c; add[rt]+=c; // cout<<rt<<"区间的和变为"<<sum[rt]<<endl; return ; } int m=(l+r)>>1; pushdown(l,r,rt); if(L<=m) update(L,R,c,lson); if(R>m) update(L,R,c,rson); pushup(rt); } long long query(int L,int R,int l,int r,int rt) { if(L<=l&&R>=r) { // cout<<rt<<"区间贡献"<<sum[rt]<<endl; return sum[rt]; } int m=(l+r)>>1; pushdown(l,r,rt); long long ans=0; if(L<=m) ans+=query(L,R,lson); if(R>m) ans+=query(L,R,rson); return ans; } int main() { #ifndef ONLINE_JUDGE freopen("C:\\Users\\pc\\Desktop\\input.txt","r",stdin); #endif // ios::sync_with_stdio(false);//无法用scanf和输入挂 int n,m; while(cin>>n>>m) { memset(add,0,sizeof add); memset(sum,0,sizeof sum); build(1,n,1); while(m--) { string a; cin>>a; // cout<<a<<endl; if(a[0]=='Q') { long long s,t; scanf("%I64d%I64d",&s,&t); printf("%I64d\n",query(s,t,1,n,1)); continue; } if(a[0]=='C') { long long s,t,c; scanf("%I64d%I64d%I64d",&s,&t,&c); update(s,t,c,1,n,1); } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator