UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213102#584. t3raywu024365ms30380kbC++4.8kb2024-11-09 19:59:222024-11-09 23:10:43

answer

#include <bits/stdc++.h>
#define _for(i, a, b)  for (int i = (a); i <= (b); i ++ )
#define ll long long
using namespace std;
const int N = 1e5 + 5, P = 1e9 + 7; const ll inf = (ll)1e18 + 5;
int n, q, a[N];
struct Node { ll s[11]; } t;
inline Node operator + (Node u, Node v) {
	Node res;
	_for (i, 0, 10)  res.s[i] = u.s[i] + v.s[i];
	return res;
}
inline void Add(ll & x, ll y) { (x += y) %= P; }
inline void Mul(ll & x, ll y) { (x *= y) %= P; }
inline ll pw(ll a, int b) {
	ll res = 1;
	while (b) {
		if (b & 1)  Mul(res, a);
		Mul(a, a), b >>= 1;
	}
	return res;
}
struct Seg_Tree {
	#define lc (p << 1)
	#define rc (p << 1 | 1)
	#define val(p)  tr[p].val
	#define tag_add(p)  tr[p].tag_add
	#define tag_cov(p)  tr[p].tag_cov
	#define mid ((tr[p].l + tr[p].r) >> 1)
	struct Tree { int l, r; ll tag_add, tag_cov; Node val; } tr[N << 2];
	inline int len(int p) { return tr[p].r - tr[p].l + 1; }
	inline bool In(int p, int l, int r) { return l <= tr[p].l && tr[p].r <= r; }
	inline void push_tag_add(int p, ll k) {
		t = val(p), Add(tag_add(p), k);
		val(p).s[0] = len(p);
		val(p).s[1] = (t.s[1] + k * len(p) % P) % P;
		val(p).s[2] = (t.s[2] + 2ll * k % P * t.s[1] % P + pw(k, 2) * len(p) % P) % P;
		val(p).s[3] = (t.s[3] + 3ll * k % P * t.s[2] % P + 3ll * pw(k, 2) % P * t.s[1] % P + pw(k, 3) * len(p) % P) % P;
		val(p).s[4] = (t.s[4] + 4ll * k % P * t.s[3] % P + 6ll * pw(k, 2) % P * t.s[2] % P + 4ll * pw(k, 3) % P * t.s[1] % P + pw(k, 4) * len(p) % P) % +p;
		val(p).s[5] = (t.s[5] + 5ll * k % P * t.s[4] % P + 10ll * pw(k, 2) % P * t.s[3] % P + 10ll * pw(k, 3) % P * t.s[2] % P + 5ll * pw(k, 4) % P * t.s[1] % P + pw(k, 5) * len(p) % P) % P;
		val(p).s[6] = (t.s[6] + 6ll * k % P * t.s[5] % P + 15ll * pw(k, 2) % P * t.s[4] % P + 20ll * pw(k, 3) % P * t.s[3] % P + 15ll * pw(k, 4) % P * t.s[2] % P + 6ll * pw(k, 5) % P * t.s[1] % P + pw(k, 6) * len(p) % P) % P;
		val(p).s[7] = (t.s[7] + 7ll * k % P * t.s[6] % P + 21ll * pw(k, 2) % P * t.s[5] % P + 35ll * pw(k, 3) % P * t.s[4] % P + 35ll * pw(k, 4) % P * t.s[3] % P + 21ll * pw(k, 5) % P * t.s[2] % P + 7ll * pw(k, 6) % P * t.s[1] % P + pw(k, 7) * len(p)) % P;
		val(p).s[8] = (t.s[8] + 8ll * k % P * t.s[7] % P + 28ll * pw(k, 2) % P * t.s[6] % P + 56ll * pw(k, 3) % P * t.s[5] % P + 70ll * pw(k, 4) % P * t.s[4] % P + 56ll * pw(k, 5) % P * t.s[3] % P + 28ll * pw(k, 6) % P * t.s[2] % P + 8ll * pw(k, 7) % P * t.s[1] % P + pw(k, 8) * len(p)) % P;
		val(p).s[9] = (t.s[9] + 9ll * k % P * t.s[8] % P + 36ll * pw(k, 2) % P * t.s[7] % P + 84ll * pw(k, 3) % P * t.s[6] % P + 126ll * pw(k, 4) % P * t.s[5] % P + 126ll * pw(k, 5) % P * t.s[4] % P + 84ll * pw(k, 6) % P * t.s[3] % P + 36ll * pw(k, 7) % P * t.s[2] % P + 9ll * pw(k, 8) % P * t.s[1] % P + pw(k, 9) * len(p)) % P;
		val(p).s[10] = (t.s[10] + 10ll * k % P * t.s[9] % P + 45ll * pw(k, 2) % P * t.s[8] % P + 120ll * pw(k, 3) % P * t.s[7] % P + 210ll * pw(k, 4) % P * t.s[6] % P + 252ll * pw(k, 5) % P * t.s[5] % P + 210ll * pw(k, 6) % P * t.s[4] % P + 120ll * pw(k, 7) % P * t.s[3] % P + 45ll * pw(k, 8) % P * t.s[2] % P + 10ll * pw(k, 9) % P * t.s[1] % P + pw(k, 10) * len(p)) % P;
	}
	inline void push_tag_cov(int p, ll k) {
		tag_cov(p) = k;
		_for (i, 0, 10)  val(p).s[i] = pw(k, i) * len(p);
	}
	inline void push_up(int p) { val(p) = val(lc) + val(rc); }
	inline void push_down(int p) {
		if (tag_add(p))  push_tag_add(lc, tag_add(p)), push_tag_add(rc, tag_add(p)), tag_add(p) = 0;
		if (tag_cov(p) ^ inf)  push_tag_cov(lc, tag_cov(p)), push_tag_cov(rc, tag_cov(p)), tag_cov(p) = inf;
	}
	void build(int p, int l, int r) {
		tr[p].l = l, tr[p].r = r, tag_add(p) = 0, tag_cov(p) = inf;
		if (l == r) {
			_for (i, 0, 10)  val(p).s[i] = pw(a[l], i);
			return ;
		}
		build(lc, l, mid), build(rc, mid + 1, r), push_up(p);
	}
	void update_add(int p, int l, int r, ll k) {
		if (In(p, l, r))  return push_tag_add(p, k), void();
		push_down(p);
		if (l <= mid)  update_add(lc, l, r, k);
		if (r > mid)  update_add(rc, l, r, k);
		push_up(p);
	}
	void update_cov(int p, int l, int r, ll k) {
		if (In(p, l, r))  return push_tag_cov(p, k), void();
		push_down(p);
		if (l <= mid)  update_cov(lc, l, r, k);
		if (r > mid)  update_cov(rc, l, r, k);
		push_up(p);
	}
	Node query(int p, int l, int r) {
		if (In(p, l, r))  return val(p);
		push_down(p);
		if (r <= mid)  return query(lc, l, r);
		if (l > mid)  return query(rc, l, r);
		return query(lc, l, r) + query(rc, l, r);
	}
	#undef lc
	#undef rc
	#undef mid
} T;
int main() {
	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> q; int op, l, r; ll k;
	_for (i, 1, n)  cin >> a[i];
	T.build(1, 1, n);
	while (q -- ) {
		cin >> op >> l >> r >> k;
		if (op == 1)  T.update_add(1, l, r, k);
		else if (op == 2)  T.update_cov(1, l, r, k);
		else  cout << T.query(1, l, r).s[k] << "\n";
	}
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 15ms
memory: 1424kb

input:

458 823
14431 9895 11970 15308 2575 20181 709 27999 12992 18884 11061 16281 5044 28990 25092 28337 3...

output:

158806085202
11228004901
13581509598
49903754914
101381317032
68789204149
71147653011
54494554728
22...

result:

wrong answer 1st lines differ - expected: '806084096', found: '158806085202'

Test #2:

score: 0
Wrong Answer
time: 6ms
memory: 1420kb

input:

481 526
8409 14498 18636 10027 24362 32458 17986 17730 11956 19192 2193 1034 29317 19284 16210 26242...

output:

106867105839
51717266270
93288311841
107320453100
133
126208311423
113396879745
41216488317
28169215...

result:

wrong answer 1st lines differ - expected: '867105097', found: '106867105839'

Test #3:

score: 0
Wrong Answer
time: 3275ms
memory: 30380kb

input:

100000 100000
15247 4194 9619 4532 22058 2667 21549 16652 25327 12018 13395 11426 7243 11714 22904 2...

output:

54433
544457741
352487648
82525935
532381851
1235929457
38218
30045720
19138
442171269
33559
7741265...

result:

wrong answer 6th lines differ - expected: '235929450', found: '1235929457'

Test #4:

score: 0
Wrong Answer
time: 3411ms
memory: 30376kb

input:

100000 100000
6264 26207 28424 24165 4852 20798 5803 18679 24588 12238 25786 28622 19900 101 25922 2...

output:

18923
13111195
41716
34447
32091
80654
2245127867
9973
309425984
19797
2443038054
407688980
3136
867...

result:

wrong answer 7th lines differ - expected: '731180277', found: '2245127867'

Test #5:

score: 0
Wrong Answer
time: 3713ms
memory: 30372kb

input:

100000 100000
15043 9299 7163 25384 24996 3803 24356 12466 22073 12987 8931 14997 3951 32704 23076 8...

output:

10841754422984
6296
588341566
13754615771606
173602590
683
7654574331434
63953
57030
17635
773175227...

result:

wrong answer 1st lines differ - expected: '754347097', found: '10841754422984'

Test #6:

score: 0
Wrong Answer
time: 3836ms
memory: 30380kb

input:

100000 100000
14736 16956 19864 23894 29403 5507 12182 6188 17192 14440 18618 3970 15396 15037 23334...

output:

17008
73008
889765488
1013985415
15383
25232
43936237163970
75334
25854
46510
591782785
2058286195
8...

result:

wrong answer 3rd lines differ - expected: '935797904', found: '889765488'

Test #7:

score: 0
Wrong Answer
time: 1478ms
memory: 15852kb

input:

50000 50000
17799 29763 25337 21321 1391 31852 27418 28753 18524 14044 15976 18893 12274 22834 11348...

output:

19498
701473302110
15649696058320
1279736265015
1405050640595
2656947940687
378369629892
13306558787...

result:

wrong answer 2nd lines differ - expected: '473297203', found: '701473302110'

Test #8:

score: 0
Wrong Answer
time: 1627ms
memory: 15852kb

input:

50000 50000
10654 14956 14287 25326 8102 30579 11682 23553 272 22672 14460 30241 13026 12738 4912 72...

output:

2391632650170
131706093
1369580492233
62082660634
19717811739
410128159255
10388
4939
12850529104473...

result:

wrong answer 1st lines differ - expected: '717018991', found: '2391632650170'

Test #9:

score: 0
Wrong Answer
time: 3324ms
memory: 30344kb

input:

90000 90000
29538 28214 24706 30393 27759 9002 13458 10243 15713 14881 10630 5593 7942 24578 29370 1...

output:

21939738989311
211691502
3888
373044011
37270
3409872587562
1057223594
3202426090346
15058366002668
...

result:

wrong answer 1st lines differ - expected: '738835738', found: '21939738989311'

Test #10:

score: 0
Wrong Answer
time: 3680ms
memory: 30376kb

input:

100000 100000
23515 49 31372 25112 16779 21279 30735 32743 14678 15189 1763 23114 32215 14873 20487 ...

output:

33759576971363
29199562714071
1996059253099
1782662185576
9825077009504
14962705251332
939879275854
...

result:

wrong answer 1st lines differ - expected: '576735050', found: '33759576971363'