Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

CE了???

Posted by 455675787 at 2018-08-06 21:39:27 on Problem 3468
//AC:https://www.luogu.org/recordnew/show/9383116
//No bits/stdc++.h
code:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#define ll long long
using namespace std;

const ll INF=2147483647;

ll a[100010],n,m;
struct Segmet_Tree{
	ll l,r,sum,add;
}Tree[100010*4];

void build(ll p,ll l,ll r){
	Tree[p].l=l; Tree[p].r=r;
	if(l==r){
		Tree[p].sum=a[l];
		return;
	}
	ll mid=(l+r)/2;
	build(p*2,l,mid);
	build(p*2+1,mid+1,r);
	Tree[p].sum=Tree[p*2].sum+Tree[p*2+1].sum;
}

inline void spread(ll p){
	if(Tree[p].add){
		Tree[p*2].sum+=Tree[p].add*(Tree[p*2].r-Tree[p*2].l+1);
		Tree[p*2+1].sum+=Tree[p].add*(Tree[p*2+1].r-Tree[p*2+1].l+1);
		Tree[p*2].add+=Tree[p].add;
		Tree[p*2+1].add+=Tree[p].add;
		Tree[p].add=0;
	}
}

void change(ll p,ll l,ll r,ll d){
	if(l<=Tree[p].l&&r>=Tree[p].r){
		Tree[p].sum+=(ll)d*(Tree[p].r-Tree[p].l+1);
		Tree[p].add+=d;
		return;
	}
	spread(p);
	ll mid=(Tree[p].l+Tree[p].r)/2;
	if(l<=mid) change(p*2,l,r,d);
	if(r>mid) change(p*2+1,l,r,d);
	Tree[p].sum=Tree[p*2].sum+Tree[p*2+1].sum;
}

ll query(ll p,ll l,ll r){
	if(l<=Tree[p].l&&r>=Tree[p].r) return Tree[p].sum;
	spread(p);
	ll mid=(Tree[p].l+Tree[p].r)/2,ans=0;
	if(l<=mid) ans+=query(p*2,l,r);
	if(r>mid) ans+=query(p*2+1,l,r);
	return ans;
}

inline ll read(){
    ll tmp=1,x=0;
    char ch=getchar();
    while(!isdigit(ch)){
        if(ch=='-') tmp=-1;
        ch=getchar();
    }
   
    while(isdigit(ch)){
        x=x*10+ch-48;
        ch=getchar();
    }
    return tmp*x;
}

inline void write(ll x){
    ll y=10,len=1;
    while(y<=x){
    	y*=10;
		len++;
	}
    while(len--){
		y/=10;
		putchar(x/y+48);
		x%=y;
	}
}

int main(){
	n=read(); m=read();
	for(ll i=1; i<=n; i++){
		a[i]=read();
	}
	
	build(1,1,n);
	
	while(m--){
		string pd;
		cin>>pd;
		if(pd=="C"){
			ll x=read(),y=read(),k=read();
			change(1,x,y,k);
		}
		else{
			ll x=read(),y=read();
			write(query(1,x,y));
			putchar('\n');
		}
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator