QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#726871 | #6435. Paimon Segment Tree | raywu | WA | 3ms | 33988kb | C++14 | 3.4kb | 2024-11-09 09:46:45 | 2024-11-09 09:46:45 |
Judging History
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];
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;
_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;
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];
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, A = U, A.a[0][1] = x % P, 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: 3ms
memory: 33916kb
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: 3ms
memory: 33916kb
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: 3ms
memory: 33988kb
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:
987351470 480617351 158737405 947145241 821880285 692456425 85911722 396288306 446740726 461388626 247029353 636441243 -131027691 177389866 219671905 579395893 306481205 241316769 687891996 638782189 571575356 606551808 104401793 149338319 9223561 816874735 179755969 464984301 833392929 600397251 61...
result:
wrong answer 1st numbers differ - expected: '400489222', found: '987351470'