Language: C

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;

const int maxn=100010;
const long long MOD=10007;

long long sum[maxn*3][4];
long long lazyset[maxn*3], lazymult[maxn*3], lazyplus[maxn*3];
int n, l, r;
long long ans;

void BuildTree ()
{
    memset(sum, 0, sizeof(sum));
    memset(lazyset, 0, sizeof(lazyset));
    memset(lazymult, 0, sizeof(lazymult));
    memset(lazyplus, 0, sizeof(lazyplus));
}

void MaintanSet (int o, int L, int R, long long a)
{
    int x=R-L+1;
    long long a2=a*a, a3=a2*a;
    a2=a2%MOD; a3=a3%MOD;

    sum[o][1]=(a*x)%MOD;
    sum[o][2]=(a2*x)%MOD;
    sum[o][3]=(a3*x)%MOD;
}

void MaintanPlus (int o, int L, int R, long long a)
{
    int x=R-L+1;
    long long a2=a*a, a3=a2*a;
    a2=a2%MOD; a3=a3%MOD;

    sum[o][3]=(a3*x+3*a2*sum[o][1]+3*a*sum[o][2]+sum[o][3])%MOD;
    sum[o][2]=(a2*x+2*a*sum[o][1]+sum[o][2])%MOD;
    sum[o][1]=(a*x+sum[o][1])%MOD;
}

void MaintanMult (int o, int L, int R, long long a)
{
    long long a2=a*a, a3=a2*a;
    a2=a2%MOD; a3=a3%MOD;

    sum[o][3]=(a3*sum[o][3])%MOD;
    sum[o][2]=(a2*sum[o][2])%MOD;
    sum[o][1]=(a*sum[o][1])%MOD;
}

void down (int o, int L, int R)
{
    int lc=o*2, rc=lc+1;

    if(lazyset[o]){
        MaintanSet(o, L, R, lazyset[o]);
        if(L!=R) lazyset[lc]=lazyset[rc]=lazyset[o];
        lazyset[o]=0;
        return ;
    }

    if(lazymult[o]){
        MaintanMult(o, L, R, lazymult[o]);
        if(L!=R) lazymult[lc]=lazymult[rc]=lazymult[o];
        lazymult[o]=0;
    }

    if(lazyplus[o]){
        MaintanPlus(o, L, R, lazyplus[o]);
        if(L!=R) lazyplus[lc]=lazyplus[rc]=lazyplus[o];
        lazyplus[o]=0;
    }
}

void up (int o, int L, int R)
{
    int lc=o*2, rc=lc+1;

    for(int i=1; i<=3; i++){
        sum[o][i]=(sum[lc][i]+sum[rc][i])%MOD;
    }
}

void UpdatePlus (int o, int L, int R, long long a)
{
    int lc=o*2, rc=lc+1;

    if(l<=L && R<=r){
        if(lazyset[o]){
            lazyset[o]+=a;
            lazyset[o]%=MOD;
        }
        else{
            lazyplus[o]+=a;
            lazyplus[o]%=MOD;
        }
    }
    else{
        down(o, L, R);

        int M=L+(R-L)/2;
        if(l<=M) UpdatePlus(lc, L, M, a); else down(lc, L, M);
        if(r>M) UpdatePlus(rc, M+1, R, a); else down(rc, M+1, R);

        up(o, L, R);
    }
}

void UpdateMult (int o, int L, int R, long long a)
{
    int lc=o*2, rc=lc+1;

    if(l<=L && R<=r){
        if(lazyset[o]){
            lazyset[o]*=a;
            lazyset[o]%=MOD;
        }
        else{
            lazyplus[o]*=a;
            lazyplus[o]%=MOD;
            lazymult[o]*=a;
            lazymult[o]%=MOD;
        }
    }
    else{
        down(o, L, R);

        int M=L+(R-L)/2;
        if(l<=M) UpdateMult(lc, L, M, a); else down(lc, L, M);
        if(r>M) UpdateMult(rc, M+1, R, a); else down(rc, M+1, R);

        up(o, L, R);
    }
}

void UpdateSet (int o, int L, int R, long long a)
{
    int lc=o*2, rc=lc+1;

    if(l<=L && R<=r){
        lazyset[o]=a;
    }
    else{
        down(o, L, R);

        int M=L+(R-L)/2;

        if(l<=M) UpdateSet(lc, L, M, a); else down(lc, L, M);
        if(r>M) UpdateSet(rc, M+1, R, a); else down(rc, M+1, R);

        up(o, L, R);
    }
}

void Query (int o, int L, int R, long long a)
{
    int lc=o*2, rc=lc+1;

    down(o, L, R);

    if(l<=L && R<=r){
        ans+=sum[o][a];
        ans=ans%MOD;
        return ;
    }

    int M=L+(R-L)/2;
    if(l<=M) Query(lc, L, M, a);
    if(r>M) Query(rc, M+1, R, a);
}

int main()
{
    freopen("data", "r+", stdin);

    int m;

    while(scanf("%d %d", &n, &m) && n){
        BuildTree();

        while(m--){
            int q, x, y;
            long long c;
            scanf("%d %d %d %lld", &q, &x, &y, &c);
            l=x, r=y;
            switch(q){
            case 1:
                UpdatePlus(1, 1, n, c);
                break;
            case 2:
                UpdateMult(1, 1, n, c);
                break;
            case 3:
                UpdateSet(1, 1, n, c);
                break;
            case 4:
                ans=0;
                Query(1, 1, n, c);
                printf("%lld\n", ans);
                break;
            }
        }
    }

    return 0;
}

Compiler output:
main.c:1:10: fatal error: cstdio: No such file or directory
    1 | #include <cstdio>
      |          ^~~~~~~~
compilation terminated.