连线段树都不会写了,我太蒻了
这里贴综合网上各种版本后写出来的板子,备忘
luogu3372 (区间加)

#include<bits/stdc++.h>
#define _for(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define INF 0x3f3f3f3f
#define LL long long
#define MAXN 100000
#define MAXM 100000
using namespace std;

LL sum[MAXN*4],plz[MAXN*4]; // plz加法标记
int n,m;

inline int ls(int o) {return o<<1;}
inline int rs(int o) {return (o<<1)|1;}
void pushup(int o)
{
    sum[o] = sum[ls(o)] + sum[rs(o)];
}
void build(int o,int l,int r)
{
    if(l == r)
    {
        scanf("%lld",&sum[o]);
        return;
    }
    int mid = (l+r) >> 1;
    build(ls(o),l,mid);
    build(rs(o),mid+1,r);
    pushup(o);
}
void pushdown(int o,int l,int r)
{
    plz[ls(o)] += plz[o];
    plz[rs(o)] += plz[o];
    int mid = (l+r) >> 1;
    sum[ls(o)] += plz[o] * (mid-l+1);
    sum[rs(o)] += plz[o] * (r-mid);
    plz[o] = 0;
}
void update(int o,int l,int r,int x,int y,LL v) // l~r 树区间 x~y 操作区间
{
    if(x <= l && r <= y)
    {
        plz[o] += v;
        sum[o] += v * (r-l+1);
        return;
    }
    if(plz[o]) pushdown(o,l,r);
    int mid = (l+r) >> 1;
    if(x <= mid) update(ls(o),l,mid,x,y,v);
    if(y > mid) update(rs(o),mid+1,r,x,y,v);
    pushup(o);
}
LL query(int o,int l,int r,int x,int y)
{
    if(x <= l && r <= y) return sum[o];
    pushdown(o,l,r);
    LL res = 0;
    int mid = (l+r) >> 1;
    if(x <= mid) res += query(ls(o),l,mid,x,y);
    if(y > mid) res += query(rs(o),mid+1,r,x,y);
    return res;
}
int main()
{
    scanf("%d%d",&n,&m);
    build(1,1,n);
    _for(i,1,m)
    {
        int opt;
        scanf("%d",&opt);
        if(opt == 1)
        {
            int x,y;
            LL k;
            scanf("%d%d%lld",&x,&y,&k);
            update(1,1,n,x,y,k);
        }
        else
        {
            int x,y;
            scanf("%d%d",&x,&y);
            printf("%lld\n",query(1,1,n,x,y));
        }
    }
    return 0;
}

luogu3373 (区间乘)

//非结构体写法
#include<bits/stdc++.h>
#define _for(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define INF 0x3f3f3f3f
#define LL long long
#define MAXN 120000
using namespace std;

LL sum[MAXN*4],plz[MAXN*4],mlz[MAXN*4]; // plz加法标记,mlz乘法标记
//要取模!!
int n,m,p;

inline int ls(int o) {return (o<<1);}
inline int rs(int o) {return (o<<1)|1;}
void pushup(int o)
{
    sum[o] = (sum[ls(o)] + sum[rs(o)]) % p;
}
void build(int o,int l,int r)
{
    mlz[o] = 1;
    plz[o] = 0;
    if(l == r)
    {
        scanf("%lld",&sum[o]);
        return;
    }
    int mid = (l+r) >> 1;
    build(ls(o),l,mid);
    build(rs(o),mid+1,r);
    pushup(o);
}
void pushdown(int o,int l,int r)
{
    plz[ls(o)] = (plz[ls(o)] * mlz[o] + plz[o]) % p;
    plz[rs(o)] = (plz[rs(o)] * mlz[o] + plz[o]) % p;
    mlz[ls(o)] = (mlz[ls(o)] * mlz[o]) % p;
    mlz[rs(o)] = (mlz[rs(o)] * mlz[o]) % p;
    int mid = (l+r) >> 1;
    sum[ls(o)] = (sum[ls(o)] * mlz[o] + (mid-l+1) * plz[o]) % p;
    sum[rs(o)] = (sum[rs(o)] * mlz[o] + (r-mid) * plz[o]) % p;
    mlz[o] = 1;
    plz[o] = 0;
}
void update_plz(int o,int l,int r,int x,int y,int k)
{
    if(x <= l && y >= r)
    {
        plz[o] = (plz[o] + k) % p;
        sum[o] = (sum[o] + (r-l+1) * k) % p;
        return;
    }
    //*****************
    pushdown(o,l,r);
    //*****************
    int mid = (l+r) >> 1;
    if(x <= mid) update_plz(ls(o),l,mid,x,y,k);
    if(y > mid) update_plz(rs(o),mid+1,r,x,y,k);
    //*******
    pushup(o);
    //*******
}
void update_mlz(int o,int l,int r,int x,int y,int k)
{
    if(x <= l && y >= r)
    {
        mlz[o] = (mlz[o] * k) % p;
        plz[o] = (plz[o] * k) % p;
        sum[o] = (sum[o] * k) % p;
        return;
    }
    pushdown(o,l,r);
    int mid = (l+r) >> 1;
    if(x <= mid) update_mlz(ls(o),l,mid,x,y,k);
    if(y > mid) update_mlz(rs(o),mid+1,r,x,y,k);
    pushup(o);
}
LL query(int o,int l,int r,int x,int y)
{
    if(x <= l && y >= r) return sum[o];
    LL res = 0;
    int mid = (l+r) >> 1;
    pushdown(o,l,r);
    if(x <= mid) res = (res + query(ls(o),l,mid,x,y)) % p;
    if(y > mid) res = (res + query(rs(o),mid+1,r,x,y)) % p;
    return res;
}
int main()
{
    scanf("%d%d%d",&n,&m,&p);
    build(1,1,n);
    _for(i,1,m)
    {
        int opt,x,y,k;
        scanf("%d",&opt);
        if(opt == 1)
        {
            scanf("%d%d%d",&x,&y,&k);
            update_mlz(1,1,n,x,y,k);
        }
        else if(opt == 2)
        {
            scanf("%d%d%d",&x,&y,&k);
            update_plz(1,1,n,x,y,k);
        }
        else
        {
            scanf("%d%d",&x,&y);
            printf("%lld\n",query(1,1,n,x,y));
        }
    }
    return 0;
}

CF914D (区间gcd)

#include<bits/stdc++.h>
#define _for(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define INF 0x3f3f3f3f
#define MAXN 500000
using namespace std;

int n,m;
int sum[MAXN*4];
int cnt;

inline int ls(int o) {return o<<1;}
inline int rs(int o) {return (o<<1)|1;}
int gcd(int x,int y)
{
    return y ? gcd(y,x%y) : x;
}
void pushup(int o)
{
    sum[o] = gcd(sum[ls(o)],sum[rs(o)]);
}
void build(int o,int l,int r)
{
    if(l == r)
    {
        scanf("%d",&sum[o]);
        return;
    }
    int mid = (l+r) >> 1;
    build(ls(o),l,mid);
    build(rs(o),mid+1,r);
    pushup(o);
}
void update(int o,int l,int r,int x,int v) // l~r树区间 x操作点
{
    if(l == r)
    {
        sum[o] = v;
        return;
    }
    int mid = (l+r) >> 1;
    if(x <= mid) update(ls(o),l,mid,x,v);
    if(x > mid) update(rs(o),mid+1,r,x,v);
    pushup(o);
}
void query(int o,int l,int r,int x,int y,int v)
{
    if(cnt > 1) return;
    if(l == r)
    {
        cnt++;
        return;
    }
    int mid = (l+r) >> 1;
    if(x <= mid && sum[ls(o)] % v) query(ls(o),l,mid,x,y,v);
    if(y > mid && sum[rs(o)] % v) query(rs(o), mid+1,r,x,y,v);
}
int main()
{
    scanf("%d",&n);
    build(1,1,n);
    scanf("%d",&m);
    while(m--)
    {
        int opt;
        scanf("%d",&opt);
        if(opt == 1)
        {
            int x,y,v;
            scanf("%d%d%d",&x,&y,&v);
            cnt = 0;
            query(1,1,n,x,y,v);
            if(cnt > 1) printf("NO\n");
            else printf("YES\n");
        }
        else
        {
            int x,v;
            scanf("%d%d",&x,&v);
            update(1,1,n,x,v);
        }
    }
    return 0;
}

感谢:
线段树(单标记+离散化+扫描线+双标记)+zkw线段树+权值线段树+主席树及一些例题
线段树区间更新操作及Lazy思想(详解)
线段树 从入门到进阶
Senior Data Structure · 浅谈线段树(Segment Tree)