标签:orm tran cout 操作 href str iostream while problem
咕咕咕
talk is cheap, chow the code.
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
const ll N = 2e5+99;
const ll mod = 10007;
struct segment_tree {
#define pl (p << 1)
#define pr (p << 1 | 1)
struct tree {
ll data, data2 ,data3;
ll add;
ll c;
ll mul;
}tr[N << 2];
inline void pushup(ll p) {
(tr[p].data = tr[pl].data + tr[pr].data)%=mod;
(tr[p].data2 = tr[pl].data2 + tr[pr].data2) %= mod;
(tr[p].data3 = tr[pl].data3 + tr[pr].data3) %= mod;
}
inline void pushdown(ll s, ll t, ll p) {
ll mid = (s + t) >> 1;
if (tr[p].c != -1) {
(tr[pl].data = tr[p].c * (mid -s + 1))%=mod;
(tr[pl].data2 = tr[p].c*tr[p].c%mod * (mid - s + 1)) %= mod;
(tr[pl].data3 = tr[p].c *tr[p].c%mod*tr[p].c % mod * (mid - s + 1)) %= mod;
(tr[pr].data = tr[p].c * (t - mid)) %= mod;
(tr[pr].data2 = tr[p].c * tr[p].c % mod * (t - mid)) %= mod;
(tr[pr].data3 = tr[p].c *tr[p].c%mod*tr[p].c % mod * (t - mid)) %= mod;
tr[pl].c = tr[p].c;
tr[pr].c = tr[p].c;
if (tr[p].c != -1) {
tr[pl].add = tr[pr].add = 0;
tr[pl].mul = tr[pr].mul = 1;
}
}
(tr[pl].data *= tr[p].mul)%=mod;
(tr[pl].data2 *= tr[p].mul*tr[p].mul%mod) %= mod;
(tr[pl].data3 *= tr[p].mul*tr[p].mul%mod * tr[p].mul%mod) %= mod;
(tr[pr].data *= tr[p].mul) %= mod;
(tr[pr].data2 *= tr[p].mul * tr[p].mul % mod) %= mod;
(tr[pr].data3 *= tr[p].mul * tr[p].mul % mod * tr[p].mul % mod) %= mod;
(tr[pr].mul *= tr[p].mul)%=mod;
(tr[pl].mul *= tr[p].mul)%=mod;
(tr[pl].data3 += 3*tr[p].add * tr[pl].data2%mod+3*tr[p].add*tr[p].add%mod*tr[pl].data%mod + tr[p].add*tr[p].add%mod*tr[p].add%mod*(mid - s+1)%mod)%=mod;
(tr[pl].data2 += 2 * tr[p].add*(tr[pl].data)%mod+tr[p].add*tr[p].add%mod*(mid - s+1))%=mod;
(tr[pl].data += tr[p].add * (mid - s+1))%=mod;
(tr[pr].data3 += 3*tr[p].add * tr[pr].data2%mod+3*tr[p].add*tr[p].add%mod*tr[pr].data%mod + tr[p].add*tr[p].add%mod*tr[p].add%mod*(t - mid)%mod)%=mod;
(tr[pr].data2 += 2 * tr[p].add*(tr[pr].data)%mod+tr[p].add*tr[p].add%mod*(t - mid))%=mod;
(tr[pr].data += tr[p].add * (t - mid))%=mod;
(tr[pl].add *= tr[p].mul)%=mod;
(tr[pr].add *= tr[p].mul)%=mod;
(tr[pl].add += tr[p].add)%=mod;
(tr[pr].add += tr[p].add)%=mod;
tr[p].mul = 1;
tr[p].add = 0;
tr[p].c = -1;
}
inline void add(ll s, ll t, ll l, ll r, ll p, ll c) {
if (s >= l &&t <= r) {
(tr[p].add+=c)%=mod;
(tr[p].data3 += 3*c*tr[p].data2%mod+3*tr[p].data*c%mod*c%mod+c*c%mod*c%mod* ( t - s + 1)%mod) %= mod;
(tr[p].data2 += 2*c%mod * tr[p].data % mod + c * c % mod * (t - s + 1)%mod) %= mod;
(tr[p].data += c * ( t - s + 1)) %= mod;
return;
}
pushdown(s, t, p);
ll mid = (s + t) >> 1;
if (l <= mid)add(s, mid, l, r, pl, c);
if (r >= mid + 1)add(mid + 1, t, l, r, pr, c);
pushup(p);
}
inline void mul(ll s, ll t, ll l, ll r, ll p, ll c) {
if (s >= l && t <= r) {
(tr[p].mul *= c)%=mod;
(tr[p].add *= c)%=mod;
(tr[p].data *= c)%=mod;
(tr[p].data2 *= c*c%mod)%=mod;
(tr[p].data3 *= c*c%mod*c%mod)%=mod;
return;
}
pushdown(s, t, p);
ll mid = (s + t) >> 1;
if (l <= mid)mul(s, mid, l, r, pl, c);
if (r >= mid + 1)mul(mid + 1, t, l, r,pr, c );
pushup(p);
}
inline void change(ll s, ll t, ll l, ll r, ll p, ll c) {
if (s >= l && t <= r) {
tr[p].c = c;
tr[p].add = 0;
tr[p].mul = 1;
(tr[p].data = c*(t-s+1))%=mod;
(tr[p].data2 = c*c%mod*(t-s+1))%=mod;
(tr[p].data3 = c*c%mod*c%mod*(t-s+1)%mod)%=mod;
return;
}
pushdown(s, t, p);
ll mid = (s + t ) >> 1;
if (l <= mid)change(s, mid, l ,r, pl, c);
if (r > mid)change(mid + 1, t, l, r, pr, c);
pushup(p);
}
inline ll query(ll s, ll t, ll l, ll r, ll p, ll c) {
ll mid = (s + t >> 1);
pushdown(s, t, p);
if (s >= l && t <= r) {
if (c == 1)
return tr[p].data;
if(c == 2)return tr[p].data2;
if (c == 3)return tr[p].data3;
}
ll ret = 0;
if (l <= mid) (ret += query(s, mid, l, r, pl, c))%=mod;
if (r > mid) (ret += query(mid + 1, t, l, r, pr, c))%=mod;
return ret;
}
inline void build(ll s, ll t, ll p) {
tr[p].add = tr[p].data = tr[p].data2 = tr[p].data3 = 0;
tr[p].c = -1;
tr[p].mul = 1;
if (s == t) {
tr[p].data = 0;
return;
}
ll mid = s+ t>>1;
build(s, mid, pl);
build(mid + 1, t, pr);
pushup(p);
return;
}
}T;
int main() {
ll n, m;
ios::sync_with_stdio(0);
while (cin >> n >> m) {
if (n == 0 && m == 0)break;
memset(T.tr, 0, sizeof T.tr);
T.build(1, n, 1);
while (m--) {
ll opt;cin >> opt;
ll x, y, c;
cin >> x >> y >> c;
if (opt == 1)
T.add(1, n, x, y, 1, c%mod);
if (opt == 2)
T.mul(1, n, x, y, 1, c%mod);
if (opt == 3)
T.change(1, n, x, y, 1, c%mod);
if (opt == 4)
cout << T.query(1, n, x, y, 1, c) <<‘\n‘;
}
}
return 0;
}
标签:orm tran cout 操作 href str iostream while problem
原文地址:https://www.cnblogs.com/Xiao-yan/p/14157025.html