LOJ - #6283. 数列分块入门 7

题目链接: https://ajax.loj.ac/problem/6283

#include<bits/stdc++.h>
#define ll long long
#define mod 10007
using namespace std;
const int maxn = 1e5 + 5;
int blo, opt, l, r, c, n, m;
int pos[maxn], a[maxn], mtag[maxn], atag[maxn];
void reset(int x)
{
    for (int i = (x-1)*blo+1; i <= min(x*blo, n); i++){
        a[i] = (a[i]*mtag[x] + atag[x]) % mod;
    }
    mtag[x] = 1, atag[x] = 0;
}
int solve (int opt, int l , int r, int c)
{
    reset(pos[l]);
    for (int i = l; i <= min(pos[l]*blo, r); i++)
    {
        if(opt == 0) a[i] += c;
        else a[i] *= c;
        a[i] %= mod;
    }
    if(pos[l] != pos[r])
    {
        reset(pos[r]);
        for (int i = (pos[r]-1)*blo + 1; i <= r; i++)
        {
            if(opt == 0) a[i] += c;
            else a[i] *= c;
            a[i] %= mod;
        }
    }
    for (int i = pos[l]+1; i <= pos[r]-1; i++)
    {
        if(opt == 0) atag[i] = (atag[i] + c) % mod;
        else{
            atag[i] = (atag[i] * c) % mod;
            mtag[i] = (mtag[i] * c) % mod;
        }
    }
}
int main()
{
    scanf("%d", &n);
    blo = sqrt(n);
    for (int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        pos[i] = (i-1)/blo+1;
        mtag[pos[i]] = 1;
    }
    for (int i = 0; i < n; i++){
        scanf("%d%d%d%d", &opt, &l, &r, &c);
        if(opt == 2) printf("%d\n",(a[r]*mtag[pos[r]]+atag[pos[r]])% mod);
        else solve(opt, l, r, c);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37602930/article/details/81221632