QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#726878#6435. Paimon Segment TreeraywuWA 5ms35432kbC++143.6kb2024-11-09 09:52:492024-11-09 09:52:50

Judging History

你现在查看的是最新测评结果

  • [2024-11-09 09:52:50]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:35432kb
  • [2024-11-09 09:52:49]
  • 提交

answer

#include <bits/stdc++.h>
#define _for(i, a, b)  for (int i = (a); i <= (b); i ++ )
#define PII pair<int, int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
const int N = 5e4 + 5, P = 1e9 + 7;
int n, m, q, a[N]; vector<PII > vec[N]; vector<int> ans[N];
inline void Add(int & x, int y) { x = x + y > P ? x + y - P : x + y; }
struct Operation { int l, r, v; } op[N];
struct Query { int a, b, c, d; } qry[N];
struct Matrix {
	int a[4][4], op = 0;
	Matrix () { _for (i, 0, 3)  _for (j, 0, 3)  a[i][j] = 0; }
	inline void unit() {
		memset(a, 0, sizeof(a));
		_for (i, 0, 3)  a[i][i] = 1;
	}
	inline Matrix operator + (Matrix t) {
		Matrix res;
		_for (i, 0, 3)  _for (j, 0, 3)  res.a[i][j] = (a[i][j] + t.a[i][j]) % P;
		return res;
	}
	inline void operator += (Matrix t) { * this = * this + t; }
	inline Matrix operator * (Matrix t) {
		Matrix res; int x;
		if (op) {
			res.op = 1;
			_for (i, 0, 3)  _for (j, 0, 3)  Add(res.a[0][j], 1ll * a[0][i] * t.a[i][j]);
			return res;
		}
		_for (i, 0, 3)  _for (k, 0, 3) {
			x = a[i][k];
			_for (j, 0, 3)  Add(res.a[i][j], 1ll * x * t.a[k][j] % P);
		}
		return res;
	}
	inline void operator *= (Matrix x) { * this = * this * x; }
} U, E, A;
struct Seg_Tree {
	#define lc (p << 1)
	#define rc (p << 1 | 1)
	#define tag(p)  tr[p].tag
	#define val(p)  tr[p].val
	#define mid ((tr[p].l + tr[p].r) >> 1)
	struct Tree { int l, r; Matrix val, tag; } 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(int p, Matrix k) { tag(p) *= k, val(p) *= k; }
	inline void push_up(int p) { val(p) = val(lc) + val(rc); }
	inline void push_down(int p) { push_tag(lc, tag(p)), push_tag(rc, tag(p)), tag(p) = U; }
	void build(int p, int l, int r) {
		tr[p].l = l, tr[p].r = r, tag(p) = U, val(p) = E, val(p).op = 1;
		if (l == r) { val(p).a[0][0] = 1, val(p).a[0][1] = a[l] % P, val(p).a[0][2] = val(p).a[0][3] = 1ll * a[l] * a[l] % P; return ; }
		build(lc, l, mid), build(rc, mid + 1, r), push_up(p);
	}
	void update(int p, int l, int r, Matrix k) {
		if (l > r)  return ;
		if (In(p, l, r))  return push_tag(p, k), void();
		push_down(p);
		if (l <= mid)  update(lc, l, r, k);
		if (r > mid)  update(rc, l, r, k);
		push_up(p);
	}
	Matrix query(int p, int l, int r) {
		if (In(p, l, r))  return val(p);
		push_down(p); Matrix res = E;
		if (l <= mid)  res += query(lc, l, r);
		if (r > mid)  res += query(rc, l, r);
		return res;
	}
	#undef lc
	#undef rc
	#undef mid
} T;
int main() {
	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m >> q, U.unit(); int l, r, x, y;
	_for (i, 1, n)  cin >> a[i], Add(a[i], P);
	T.build(1, 1, n);
	_for (i, 1, m)  cin >> op[i].l >> op[i].r >> op[i].v;
	_for (i, 1, q)  cin >> l >> r >> x >> y, qry[i].a = vec[x].size(), qry[i].b = x, vec[x].pb(mp(l, r)), qry[i].c = vec[y + 1].size(), qry[i].d = y + 1, vec[y + 1].pb(mp(l, r));
	for (PII i : vec[0])  ans[0].pb(0);
	for (PII i : vec[1])  ans[1].pb(T.query(1, i.F, i.S).a[0][3]);
	_for (_, 1, m) {
		l = op[_].l, r = op[_].r, x = op[_].v, Add(x, P), A = U, A.a[0][1] = x, A.a[0][2] = A.a[0][3] = 1ll * x * x % P, A.a[1][2] = A.a[1][3] = 2ll * x % P, A.a[2][3] = 1, T.update(1, l, r, A), A = U, A.a[2][3] = 1, T.update(1, 1, l - 1, A), T.update(1, r + 1, n, A);
		for (PII i : vec[_ + 1])  ans[_ + 1].pb(y = T.query(1, i.F, i.S).a[0][3]);
	}
	_for (i, 1, q)  cout << (ans[qry[i].d][qry[i].c] - ans[qry[i].b][qry[i].a] + P) % P << "\n";
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 35432kb

input:

3 1 1
8 1 6
2 3 2
2 2 0 0

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 5ms
memory: 35432kb

input:

4 3 3
2 3 2 2
1 1 6
1 3 3
1 3 6
2 2 2 3
1 4 1 3
4 4 2 3

output:

180
825
8

result:

ok 3 number(s): "180 825 8"

Test #3:

score: -100
Wrong Answer
time: 5ms
memory: 35424kb

input:

100 107 180
-280960553 266308104 -997644864 856103777 592874377 674379235 -946339772 641750362 642418716 -360811715 -555543246 206614021 358239245 349842656 983198973 807518446 -66612455 -980932737 109826132 -109676067 51226145 452115561 -42729559 -950621304 -87009773 714026474 375317493 693260053 -...

output:

223986906
800986868
-73310053
726346581
47850999
503771084
380958090
982905172
116935883
891675788
747212669
868300156
10417810
972860640
635827550
415191763
762150671
697048759
770617015
807341846
298038324
16105
25711377
779307061
449929850
35384072
457703499
-307929010
40706159
216820547
70602599...

result:

wrong answer 1st numbers differ - expected: '400489222', found: '223986906'