总之,今天是一个值得纪念的伟大日子,我将自己的码风进行了彻底的修改,大概是参考了Pks和\(Rqy\)的码风,分为以下几点。
1.变量名。在所有的计算符号之前和之后加空格。如:"&","|","!","\(+\)","\(-\)","\(\times\)","\(/\)"这些运算符。两个相邻的计算符之间不加空格。

原版:

while(c<'0'||c>'9') c=getchar();

后版:

while(c < '0' || c > '9') c = getchar();

2.逗号。每一个逗号之后都跟一个空格,比如:

LL A, B, C, Mark, N, M, Value[MAXN];

3.变量名。尽可能多的使用大写字符和下划线。
例:原版线段树1

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 1000010
using namespace std;
long long value[MAXN],tag[MAXN];
struct point
{
    long long left;
    long long right;
    long long sum;
}edge[MAXN*4];
#define leftson now*2
#define rightson now*2+1
void update(long long now)
{
    edge[now].sum=edge[leftson].sum+edge[rightson].sum;
}
void build(long long left,long long right,long long now)
{
    if(left==right)
    {
        edge[now].sum=value[left];
        return ;
    }
    long long mid=(left+right)/2;
    build(left,mid,now*2);
    build(mid+1,right,now*2+1);
    update(now);
}
void put(long long now,long long mid,long long left,long long right)
{
    if(tag[now])
    {
        tag[leftson]+=tag[now];
        tag[rightson]+=tag[now];
        edge[leftson].sum+=(mid-left+1)*tag[now];
        edge[rightson].sum+=(right-mid)*tag[now];
        tag[now]=0;
    }
}
void change(long long left,long long right,long long now,long long v,long long now_left,long long now_right)
{
    if(now_left<=left)
    if(now_right>=right)
    {
        tag[now]+=v;
        edge[now].sum+=(right-left+1)*v;
        return ;
    }
    long long mid=(left+right)/2;
    put(now,mid,left,right);
    if(now_left<=mid)
    change(left,mid,now*2,v,now_left,now_right);
    if(mid<now_right)
    change(mid+1,right,now*2+1,v,now_left,now_right);
    update(now);
}
long long ask(long long left,long long right,long long now,long long now_left,long long now_right)
{
    long long ans=0;
    if(now_left<=left)
    if(now_right>=right)
    return edge[now].sum;
    long long mid=(left+right)/2;
    put(now,mid,left,right);
    if(mid>=now_left)
    ans+=ask(left,mid,now*2,now_left,now_right);
    if(mid<now_right)
    ans+=ask(mid+1,right,now*2+1,now_left,now_right);
    return ans;
}
int main()
{
    long long n,m;
    scanf("%lld%lld",&n,&m);
    for(long long i=1;i<=n;i++)
        scanf("%lld",&value[i]);
    build(1,n,1);
    for(long long i=1;i<=m;i++)
    {
        long long p; scanf("%lld",&p);
        if(p==1)
        {
            long long x,y,z;
            scanf("%lld%lld%lld",&x,&y,&z);
            change(1,n,1,z,x,y);
        }
        else if(p==2)
        {
            long long x,y;
            scanf("%lld%lld",&x,&y);
            printf("%lld\n",ask(1,n,1,x,y));
        }
    }
    return 0;
}

后版

#include <iostream>
#include <cstdio>
#define MAXN 1000100
#define LL long long
#define Re register
#define LS (now << 1)
#define RS (now << 1 | 1)
#define Mid ((L + R) >>1)
#define E_Mid ((Edge[now].L + Edge[now].R) >> 1)
using namespace std;
inline void Read(LL & x){
    char c = getchar(); x = 0;
    while(c < '0' || c > '9') c = getchar();
    while(c <= '9' && c >= '0')
        x = x * 10 + c - 48, c = getchar();
}
inline void Print(LL x){
    int num = 0; char c[15];
    while(x) c[++num]=(x % 10) + 48, x /= 10;
    while(num) putchar(c[num --]);
    putchar('\n');
}
struct Node{
    LL L, R, Sum, Tag;
}Edge[MAXN << 1];
LL A, B, C, Mark, N, M, Value[MAXN];
inline void Push_Up(LL now){
    Edge[now].Sum = Edge[LS].Sum + Edge[RS].Sum;
}
inline void Push_Down(LL now){
    if(Edge[now].Tag){
        Edge[LS].Tag += Edge[now].Tag, Edge[RS].Tag += Edge[now].Tag;
        Edge[LS].Sum += Edge[now].Tag * (Edge[LS].R - Edge[LS].L + 1);
        Edge[RS].Sum += Edge[now].Tag * (Edge[RS].R - Edge[RS].L + 1);
        Edge[now].Tag = 0;
    }
}
void Build_Tree(LL now, LL L, LL R){
    if(L == R){
        Edge[now].L = L, Edge[now].R = R;
        Edge[now].Sum = Value[L];
        return ;
    }
    Edge[now].L = L;  Edge[now].R = R;
    Build_Tree(RS, Mid + 1, R); Build_Tree(LS, L, Mid);
    Push_Up(now);
}
void Add(LL now, LL L, LL R, LL K){
    if(Edge[now].L >= L && Edge[now].R <= R){
        Edge[now].Tag += K;
        Edge[now].Sum += K * (Edge[now].R - Edge[now].L + 1);
        return ;
    }   Push_Down(now);
    if(E_Mid >= L) Add(LS, L, R, K);
    if(E_Mid < R) Add(RS, L, R, K);
    Push_Up(now);
}
LL Query(LL now, LL L, LL R){
    if(Edge[now].L >= L && Edge[now].R <= R)
        return Edge[now].Sum;
    Push_Down(now); LL Ans = 0;
    if(E_Mid >= L) Ans += Query(LS, L, R);
    if(E_Mid < R) Ans += Query(RS, L, R);
    return Ans;
}
int main(){
    Read(N); Read(M);
    for(int i = 1; i <= N; i ++)
        Read(Value[i]);
    Build_Tree(1, 1, N);
    for(int i = 1; i <= M; i ++){
        Read(Mark);
        if(Mark == 1){
            Read(A); Read(B); Read(C);
            Add(1, A, B, C);
        }   else{
            Read(A); Read(B);
            Print(Query(1, A, B));
        }
    }   return 0;
}

随机推荐

  1. flight学习笔记

    Flight::db()-> getOne("select 1"); 返回结果:1 Flight::db()-> getRow ("select 1, 2 f ...

  2. k8s常用指令集(kubectl kubeadm)

    1      Kubectl指令集 1.1      Master查询节点信息 [root@master1 kubernetes-1.10]# kubectl get nodes 1.2      查 ...

  3. svn的使用总结

    在网上看到了以前介绍非常全的svn的文章,拿来分享 原文网址  http://www.cnblogs.com/jx270/archive/2013/03/04/2943595.html 还有一篇更基础 ...

  4. Java读取粘贴板内容

    package com.test.jvm.oom.design; import java.awt.Image; import java.awt.Toolkit; import java.awt.dat ...

  5. sql: T-SQL 统计计算(父子關係,樹形,分級分類的統計)

    ---sql: T-SQL 统计计算(父子關係,樹形,分級分類的統計) ---2014-08-26 塗聚文(Geovin Du) CREATE PROCEDURE proc_Select_BookKi ...

  6. 计算(calc.cpp)

    计算(calc.cpp) [问题描述] 小明在你的帮助下,破密了Ferrari设的密码门,正要往前走,突然又出现了一个密码门,门上有一个算式,其中只有“(”,“)”,“0-9”,“+”,“-”,“*” ...

  7. ioc autofac简单示例

    1.winform用法: nuget安装autofac public interface ILog { bool Log(string msg); } public class TXTLogger : ...

  8. html+css模仿的锤子官方首页

    <div id="wrapper"> <header> <div class="container"> <h1> ...

  9. Android中获取TextView行数

    项目中发现,如果直接通过TextView.getLineCount()方法获取行数时,总是0,研究发现,setText()后立即调用getLineCount(), 这时TextView还未完成meas ...

  10. 排序算法积累(2)----sort排序

    转载:http://blog.csdn.net/sunshangjin/article/details/40296357 想起来自己天天排序排序,冒泡啊,二分查找啊,结果在STL中就自带了排序函数so ...