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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值