1 条题解

  • 0
    @ 2023-1-31 9:54:55
    #include <bits/stdc++.h>
    #define int long long
    using namespace std;
    const int MOD = 10007;
    int n, opt, l, r, c;
    int a[112345];
    int SZ, CNT, ID[112345], L[1004], R[1004], add[1004], mul[1004];
    void down(int id)
    {
    
        for (int i = L[id]; i <= R[id]; i++)
            a[i] = (a[i] * mul[id] % MOD + add[id]) % MOD;
        mul[id] = 1;
        add[id] = 0;
    }
    void updateAdd(int l, int r, int c)
    {
        c %= MOD;
        if (ID[l] == ID[r])
        {
            down(ID[l]);
            for (int i = l; i <= r; i++)
                a[i] = (a[i] + c) % MOD;
            return;
        }
        down(ID[l]);
        for (int i = l; i <= R[ID[l]]; i++)
            a[i] = (a[i] + c) % MOD;
        for (int i = ID[l] + 1; i <= ID[r] - 1; i++)
            add[i] = (add[i] + c) % MOD;
        down(ID[r]);
        for (int i = L[ID[r]]; i <= r; i++)
            a[i] = (a[i]+ c) % MOD;
    }
    void updateMul(int l, int r, int c)
    {
        if (ID[l] == ID[r])
        {
            down(ID[l]);
            for (int i = l; i <= r; i++)
                a[i] = (a[i] * c) % MOD;
            return;
        }
        down(ID[l]);
        for (int i = l; i <= R[ID[l]]; i++)
            a[i] = (a[i] * c) % MOD;
        for (int i = ID[l] + 1; i <= ID[r] - 1; i++)
        {
            mul[i] = (mul[i] * c) % MOD;
            add[i] = (add[i] * c) % MOD;
        }
        down(ID[r]);
        for (int i = L[ID[r]]; i <= r; i++)
            a[i] = (a[i] * c) % MOD;
    }
    int query(int r)
    {
        return (a[r] * mul[ID[r]] + add[ID[r]]) % MOD;
    }
    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n;
        SZ = sqrt(n);
        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];
            // 1: [1, SZ], 2: [SZ + 1, 2SZ]
            ID[i] = (i - 1) / SZ + 1;
        }
        CNT = n / SZ + (n % SZ > 0);
        for (int i = 1; i <= CNT; i++)
        {
            L[i] = (i - 1) * SZ + 1;
            R[i] = i * SZ;
            add[i] = 0;
            mul[i] = 1;
        }
        for (int i = 1; i <= n; i++)
        {
            cin >> opt >> l >> r >> c;
            if (opt == 0)
                updateAdd(l, r, c);
            else if (opt == 1)
                updateMul(l, r, c);
            else
                cout << query(r) << "\n";
        }
        return 0;
    }
    
    • 1

    信息

    ID
    878
    时间
    500ms
    内存
    256MiB
    难度
    6
    标签
    递交数
    26
    已通过
    11
    上传者