题意:
有三个区间操作
1.+c
2.*c
3.=c
有一个询问区间p次幂的和(1<=p<=3)
思路:
真的吐了,各个laz之间还有关系,要先搞=c的laz,把他的左右孩子的+c *c 的laz都赋为初值,然后搞*c的laz,把那个值再给+c的laz去乘,+c的laz就常规更新一下并赋给他的孩子就行。
ac代码:1800ms 时限:5000ms
/**
* Think twice, code once.
* 1.i64eger overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-19-21.40.55 Thursday
*/
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const i64 maxn = (i64)1e5+1000;
const i64 mod = 10007;
i64 n, m, t1[maxn<<2], t2[maxn<<2], t3[maxn<<2], l1[maxn<<2], l2[maxn<<2], l3[maxn<<2];
void pushUp(int node) {
t1[node] = (t1[node<<1]+t1[node<<1|1])%mod;
t2[node] = (t2[node<<1]+t2[node<<1|1])%mod;
t3[node] = (t3[node<<1]+t3[node<<1|1])%mod;
}
void pushDown(i64 node, i64 l, i64 r) {
i64 mid = (l+r)>>1;
i64 lf = mid-l+1;
i64 rt = r-mid;
i64 c;
if (l3[node]) {
c = l3[node];
t1[node<<1] = c*lf%mod;
t1[node<<1|1] = c*rt%mod;
t2[node<<1] = c*c%mod*lf%mod;
t2[node<<1|1] = c*c%mod*rt%mod;
t3[node<<1] = c*c%mod*c%mod*lf%mod;
t3[node<<1|1] = c*c%mod*c%mod*rt%mod;
l3[node<<1] = l3[node<<1|1] = c%mod;
l2[node<<1] = l2[node<<1|1] = 1;
l1[node<<1] = l1[node<<1|1] = 0;
l3[node] = 0;
}
if (l2[node] != 1) {
c = l2[node];
t1[node<<1] = c*t1[node<<1]%mod;
t1[node<<1|1] = c*t1[node<<1|1]%mod;
t2[node<<1] = c*c%mod*t2[node<<1]%mod;
t2[node<<1|1] = c*c%mod*t2[node<<1|1]%mod;
t3[node<<1] = c*c%mod*c%mod*t3[node<<1]%mod;
t3[node<<1|1] = c*c%mod*c%mod*t3[node<<1|1]%mod;
l2[node<<1] *= c;
l2[node<<1] %= mod;
l2[node<<1|1] *= c;
l2[node<<1|1] %= mod;
l1[node<<1] *= c;
l1[node<<1] %= mod;
l1[node<<1|1] *= c;
l1[node<<1|1] %= mod;
l2[node] = 1;
}
if (l1[node]) {
c = l1[node];
t3[node<<1] += 3*t2[node<<1]%mod*c%mod+3*t1[node<<1]*c*c%mod+c*c%mod*c%mod*lf%mod;
t3[node<<1] %= mod;
t3[node<<1|1] += 3*t2[node<<1|1]%mod*c%mod+3*t1[node<<1|1]*c*c%mod+c*c%mod*c%mod*rt%mod;
t3[node<<1|1] %= mod;
t2[node<<1] += 2*c*t1[node<<1]%mod+c*c%mod*lf%mod;
t2[node<<1] %= mod;
t2[node<<1|1] += 2*c*t1[node<<1|1]%mod+c*c%mod*rt%mod;
t2[node<<1|1] %= mod;
t1[node<<1] += lf*c%mod;
t1[node<<1] %= mod;
t1[node<<1|1] += rt*c%mod;
t1[node<<1|1] %= mod;
l1[node<<1] += l1[node];
l1[node<<1] %= mod;
l1[node<<1|1] += l1[node];
l1[node<<1|1] %= mod;
l1[node] = 0;
}
}
void upd1(i64 node, i64 l, i64 r, i64 ul, i64 ur, i64 val) {
if (l >= ul && r <= ur) {
i64 len = r-l+1;
t3[node] = t3[node]+3*val%mod*t2[node]%mod+3*val%mod*val%mod*t1[node]%mod+val*val%mod*val%mod*len%mod;
t3[node] %= mod;
t2[node] = t2[node]+2*t1[node]%mod*val%mod+val*val%mod*len%mod;
t2[node] %= mod;
t1[node] = t1[node]+val*len%mod;
t1[node] %= mod;
l1[node] = l1[node]+val;
l1[node] %= mod;
return;
}
pushDown(node, l, r);
i64 mid = (l+r)>>1;
if (ul <= mid) upd1(node<<1, l, mid, ul, ur, val);
if (ur > mid) upd1(node<<1|1, mid+1, r, ul, ur, val);
pushUp(node);
}
void upd2(i64 node, i64 l, i64 r, i64 ul, i64 ur, i64 val) {
if (l >= ul && r <= ur) {
t1[node] = t1[node]*val%mod;
t2[node] = t2[node]*val%mod*val%mod;
t3[node] = t3[node]*val%mod*val%mod*val%mod;
l2[node] = l2[node]*val%mod;
l1[node] = l1[node]*val%mod;
return;
}
pushDown(node, l, r);
i64 mid = (l+r)>>1;
if (ul <= mid) upd2(node<<1, l, mid, ul, ur, val);
if (ur > mid) upd2(node<<1|1, mid+1, r, ul, ur, val);
pushUp(node);
}
void upd3(i64 node, i64 l, i64 r, i64 ul, i64 ur, i64 val) {
if (l >= ul && r <= ur) {
i64 len = r-l+1;
t1[node] = len*val%mod;
t2[node] = len*val%mod*val%mod;
t3[node] = len*val%mod*val%mod*val%mod;
l3[node] = val%mod;
l2[node] = 1;
l1[node] = 0;
return;
}
pushDown(node, l, r);
i64 mid = (l+r)>>1;
if (ul <= mid) upd3(node<<1, l, mid, ul, ur, val);
if (ur > mid) upd3(node<<1|1, mid+1, r, ul, ur, val);
pushUp(node);
}
void build(i64 node, i64 l, i64 r) {
t1[node] = t2[node] = t3[node] = 0;
l1[node] = 0;
l2[node] = 1;
l3[node] = 0;
if (l < r) {
i64 mid = (l+r)>>1;
build(node<<1, l, mid);
build(node<<1|1, mid+1, r);
}
}
i64 query(int node, int l, int r, int ql, int qr, int op) {
if (l >= ql && r <= qr) {
if (op == 1) return t1[node];
else if (op == 2) return t2[node];
else if (op == 3) return t3[node];
}
if (l < r) {
pushDown(node, l, r);
int mid = (l+r)>>1;
i64 ans = 0;
if (ql <= mid) ans = (ans+query(node<<1, l, mid, ql, qr, op))%mod;
if (qr > mid) ans = (ans+query(node<<1|1, mid+1, r, ql, qr, op))%mod;
return ans;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(10);
cout << fixed;
#ifdef LOCAL_DEFINE
freopen("input.txt", "r", stdin);
#endif
while (cin >> n >> m) {
if (!n && !m) break;
build(1, 1, n);
forn(i, m) {
i64 op, x, y, z;
cin >> op >> x >> y >> z;
if (op == 1) upd1(1, 1, n, x, y, z);
else if (op == 2) upd2(1, 1, n, x, y, z);
else if (op == 3) upd3(1, 1, n, x, y, z);
else {
cout << query(1, 1, n, x, y, z) << '\n';
}
}
}
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}