码迷,mamicode.com
首页 > 其他好文 > 详细

$Yeasion$的码风修改历程

时间:2018-08-06 22:12:32      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:line   long   clu   下划线   scanf   amp   using   getc   point   

总之,今天是一个值得纪念的伟大日子,我将自己的码风进行了彻底的修改,大概是参考了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;
}

$Yeasion$的码风修改历程

标签:line   long   clu   下划线   scanf   amp   using   getc   point   

原文地址:https://www.cnblogs.com/Yeasio-Nein/p/MaFeng.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!