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了#include <iostream> #include <cstdio> #define ll long long #define MAXN 100010 using namespace std; ll q[MAXN], q2[MAXN], sum[MAXN]; ll N, C; ll lowbit( ll x) { return x&(-x); } void add(ll *c, ll a, ll x) { while( a <= N ) { c[a] += x; a += lowbit(a); } } ll query(ll *c , ll a) { ll ans = 0; while( a > 0) { ans += c[a]; a-=lowbit(a); } return ans; } int main() { scanf("%lld %lld",&N,&C); ll temp1 = 0, temp2; for(int i=1; i<=N; i++) { scanf("%lld", &temp2); add(q, i, temp2-temp1); add(q2,i, (temp2-temp1) * i); temp1 = temp2; } char cc; ll l, r, x; for(int i=0; i<C; i++) { cin >> cc; if( cc == 'Q') { scanf("%lld %lld", &l, &r); ll a, b; a = l * query(q, l-1) - query(q2, l-1); b = (r+1) * query(q, r) - query( q2, r); printf("%lld\n",b-a); }else { scanf("%lld %lld %lld", &l, &r, &x); add( q, l, x); add( q, r+1, -x); add( q2, l, l*x); add( q, r+1, (r+1)*(-x)); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator