链接:
题意:
给出一个长为 的数列,以及 个操作,操作涉及区间乘法,区间加法,单点询问。
思路:
考虑整块的乘法, 同时对整块的add标记也要乘,对单点操作时, 注意要对整块暴力修改完再操作.
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
//#include <memory.h>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <stack>
#include <string>
#include <assert.h>
#include <iomanip>
#define MINF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e6+10;
const int MOD = 10007;
LL a[MAXN], TagMul[MAXN], TagAdd[MAXN];
int Belong[MAXN];
int n, part, last;
void Reset(int pos)
{
for (int i = (pos-1)*part+1;i <= pos*part;i++)
a[i] = ((a[i]*TagMul[pos])%MOD+TagAdd[pos])%MOD;
TagAdd[pos] = 0;
TagMul[pos] = 1;
}
void UpdateAdd(int l, int r, int c)
{
Reset(Belong[l]);
for (int i = l;i <= min(r, Belong[l]*part);i++)
a[i] = (a[i]+c)%MOD;
if (Belong[l] != Belong[r])
{
Reset(Belong[r]);
for (int i = max(l, (Belong[r]-1)*part+1);i <= r;i++)
a[i] = (a[i]+c)%MOD;
}
for (int i = Belong[l]+1;i <= Belong[r]-1;i++)
TagAdd[i] = (TagAdd[i]+c)%MOD;
}
void UpdateMul(int l, int r, int c)
{
Reset(Belong[l]);
for (int i = l;i <= min(r, Belong[l]*part);i++)
a[i] = (a[i]*c)%MOD;
if (Belong[l] != Belong[r])
{
Reset(Belong[r]);
for (int i = max(l, (Belong[r]-1)*part+1);i <= r;i++)
a[i] = (a[i]*c)%MOD;
}
for (int i = Belong[l]+1;i <= Belong[r]-1;i++)
{
TagMul[i] = (TagMul[i]*c)%MOD;
// cout << i << ' ' << TagMul[i] << endl;
TagAdd[i] = (TagAdd[i]*c)%MOD;
}
}
int Query(int l, int r, int c)
{
int p = Belong[r];
// cout << a[r] << ' ' << TagMul[p] << ' ' << TagAdd[p] << endl;
return ((a[r]*TagMul[p])%MOD+TagAdd[p])%MOD;
}
int main()
{
scanf("%d", &n);
part = sqrt(n);
for (int i = 1;i <= n;i++)
{
TagMul[i] = 1;
scanf("%lld", &a[i]);
Belong[i] = (i-1)/part+1;
}
int op, l, r, c;
for (int i = 1;i <= n;i++)
{
scanf("%d", &op);
if (op == 0)
{
scanf("%d%d%d", &l, &r, &c);
UpdateAdd(l, r, c);
}
else if (op == 1)
{
scanf("%d%d%d", &l, &r, &c);
UpdateMul(l, r, c);
}
else
{
scanf("%d%d%d", &l, &r, &c);
printf("%d
", Query(l, r, c));
}
}
return 0;
}