一.题目链接:

ZOJ-3998

二.题目大意:

给你 n 个数 a[1 ~ n].

现有 3 种 m 次操作:

① l r v 将 a[l ~ r] 的数都乘以 v

② l r v 将 a[l ~ r] 的数变为 a[l]^v....a[r]^v

③ l r 查询 a[l] ×......× a[r].

三.分析:

双懒惰标记的线段树.

详见代码吧...

四.代码实现:

#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define eps 1e-6
#define pi acos(-1.0)
#define ll long long int
using namespace std;

const int M = (int)1e5;
const int mod = 1000000007;

struct node
{
    int l;
    int r;
    ll w;
    ll f1;
    ll f2;
}tree[M * 4 + 5];

ll ans;

void build(int k, int l, int r)
{
    tree[k].l = l;
    tree[k].r = r;
    tree[k].f1 = tree[k].f2 = 1;
    if(l == r)
    {
        scanf("%lld", &tree[k].w);
        return;
    }
    int mid = (l + r) / 2;
    build(k * 2, l, mid);
    build(k * 2 + 1, mid + 1, r);
    tree[k].w = tree[k * 2].w * tree[k * 2 + 1].w % mod;
}

ll quick(ll a, ll b)
{
    ll sum = 1;
    while(b)
    {
        if(b & 1)
            sum = sum * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return sum % mod;
}

void push(int k)
{
    tree[k * 2].f2 = tree[k * 2].f2 * tree[k].f2 % (mod - 1);
    tree[k * 2 + 1].f2 = tree[k * 2 + 1].f2 * tree[k].f2 % (mod - 1);
    tree[k * 2].f1 = quick(tree[k * 2].f1, tree[k].f2) * tree[k].f1 % mod;
    tree[k * 2 + 1].f1 = quick(tree[k * 2 + 1].f1, tree[k].f2) * tree[k].f1 % mod;
    tree[k * 2].w = quick(tree[k * 2].w, tree[k].f2) * quick(tree[k].f1, tree[k * 2].r - tree[k * 2].l + 1) % mod;
    tree[k * 2 + 1].w = quick(tree[k * 2 + 1].w, tree[k].f2) * quick(tree[k].f1, tree[k * 2 + 1].r - tree[k * 2 + 1].l + 1) % mod;
    tree[k].f1 = tree[k].f2 = 1;
}

void interver(int k, int l, int r, int a, int b, ll c, bool flag)
{
    if(l >= a && r <= b)
    {
        if(!flag)
        {
            tree[k].f1 = tree[k].f1 * c % mod;
            tree[k].w = tree[k].w * quick(c, tree[k].r - tree[k].l + 1ll) % mod;
            return;
        }
        else
        {
            tree[k].w = quick(tree[k].w, c);
            tree[k].f1 = quick(tree[k].f1, c);
            tree[k].f2 = tree[k].f2 * c % (mod - 1);
            return;
        }
    }
    push(k);
    int mid = (l + r) / 2;
    if(a <= mid)
        interver(k * 2, l, mid, a, b, c, flag);
    if(mid < b)
        interver(k * 2 + 1, mid + 1, r, a, b, c, flag);
    tree[k].w = tree[k * 2].w * tree[k * 2 + 1].w % mod;
}

void query(int k, int l, int r, int a, int b)
{
    if(l >= a && r <= b)
    {
        ans = ans * tree[k].w % mod;
        return;
    }
    push(k);
    int mid = (l + r) / 2;
    if(a <= mid)
        query(k * 2, l, mid, a, b);
    if(mid < b)
        query(k * 2 + 1, mid + 1, r, a, b);
    tree[k].w = tree[k * 2].w * tree[k * 2 + 1].w % mod;
}

int main()
{
    int T;
    scanf("%d", &T);
    while(T--)
    {
        int n, m;
        scanf("%d %d", &n, &m);
        build(1, 1, n);
        while((m--) > 0)
        {
            int dir, l, r;
            scanf("%d %d %d", &dir, &l, &r);
            if(dir <= 2)
            {
                ll v;
                scanf("%lld", &v);
                interver(1, 1, n, l, r, v, dir - 1);
            }
            else
            {
                ans = 1;
                query(1, 1, n, l, r);
                printf("%lld\n", ans);
            }
        }
    }
    return 0;
}