QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#719182 | #6435. Paimon Segment Tree | FUCKUCUP | WA | 3ms | 21908kb | C++20 | 4.6kb | 2024-11-06 23:07:49 | 2024-11-06 23:07:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 50010, mod = 1e9 + 7;
int n, m, q, a[maxn], ans[maxn];
struct operation { int l, r, x; }op[maxn];
struct query { int l, r, t, sgn, id; }qry[maxn << 1];
struct matrix {
matrix() { memset(x, 0, sizeof x); }
int x[4][4];
}I;
inline bool operator != (matrix &a, matrix &b) {
for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) if(a.x[i][j] != b.x[i][j]) return true;
return false;
}
inline matrix operator * (matrix &a, matrix &b) {
matrix c;
for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) for(int k = 0; k < 4; ++k) {
c.x[i][j] = (c.x[i][j] + 1ll * a.x[i][k] * b.x[k][j]) % mod;
}
return c;
}
struct node {
int sum3, sum2, sum, len;
matrix tag;
}t[maxn << 2];
inline void update(int d) {
t[d].sum3 = (t[d << 1].sum3 + t[d << 1 | 1].sum3) % mod;
t[d].sum2 = (t[d << 1].sum2 + t[d << 1 | 1].sum2) % mod;
t[d].sum = (t[d << 1].sum + t[d << 1 | 1].sum) % mod;
}
inline void calc(int &a, int &b, int &c, int &d, matrix &mt) {
int vec[4] = {a, b, c, d}, res[4] = {0, 0, 0, 0};
for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) res[i] = (res[i] + 1ll * vec[j] * mt.x[i][j]) % mod;
a = res[0], b = res[1], c = res[2], d = res[3];
}
inline void pushdown(int d) {
calc(t[d << 1].sum3, t[d << 1].sum2, t[d << 1].sum, t[d << 1].len, t[d].tag);
calc(t[d << 1 | 1].sum3, t[d << 1 | 1].sum2, t[d << 1 | 1].sum, t[d << 1 | 1].len, t[d].tag);
t[d << 1].tag = t[d << 1].tag * t[d].tag;
t[d << 1 | 1].tag = t[d << 1 | 1].tag * t[d].tag;
t[d].tag = I;
}
void build(int d, int l, int r) {
t[d].tag = I, t[d].len = r - l + 1;
// cout << l << ' ' << r << ' ' << t[d].len << '\n';
if(l == r) {
t[d].sum3 = 0;
t[d].sum2 = 1ll * a[l] * a[l] % mod;
t[d].sum = a[l];
return;
}
int md = l + r >> 1;
build(d << 1, l, md), build(d << 1 | 1, md + 1, r);
update(d);
}
void modify(int d, int l, int r, int dl, int dr, int x) {
if(dl > dr) return;
if(dl <= l && r <= dr) {
matrix tmp;
tmp.x[0][0] = tmp.x[0][1] = 1, tmp.x[0][2] = 2ll * x % mod, tmp.x[0][3] = 1ll * x * x % mod;
tmp.x[1][1] = 1, tmp.x[1][2] = 2ll * x % mod, tmp.x[1][3] = 1ll * x * x % mod;
tmp.x[2][2] = 1, tmp.x[2][3] = x;
tmp.x[3][3] = 1;
t[d].tag = tmp * t[d].tag;
calc(t[d].sum3, t[d].sum2, t[d].sum, t[d].len, tmp);
// cout << l << ' ' << r << ' ' << t[d].sum3 << ' ' << t[d].sum2 << ' ' << t[d].sum << '\n';
return;
}
if(t[d].tag != I) pushdown(d);
int md = l + r >> 1;
if(dl <= md) modify(d << 1, l, md, dl, dr, x);
if(dr > md) modify(d << 1 | 1, md + 1, r, dl, dr, x);
update(d);
}
int ask(int d, int l, int r, int dl, int dr) {
// cout << d << ' ' << l << ' ' << r << ' ' << t[12].sum3 << '\n';
if(l != r && t[d].tag != I) pushdown(d);
if(dl <= l && r <= dr) return t[d].sum3;
// if(t[d].tag != I) pushdown(d);
int md = l + r >> 1, ans = 0;
if(dl <= md) ans = ask(d << 1, l, md, dl, dr);
if(dr > md) ans = (ans + ask(d << 1 | 1, md + 1, r, dl, dr)) % mod;
return ans;
}
inline void solve() {
cin >> n >> m >> q;
for(int i = 1; i <= n; ++i) cin >> a[i], a[i] = (a[i] + mod) % mod;
op[0] = {1, n, 0};
for(int i = 1; i <= m; ++i) cin >> op[i].l >> op[i].r >> op[i].x, op[i].x = (op[i].x + mod) % mod;
for(int i = 1; i <= q; ++i) {
int l, r, x, y;
cin >> l >> r >> x >> y;
qry[i] = {l, r, x - 1, -1, i}, qry[i + q] = {l, r, y, 1, i};
}
q <<= 1, sort(qry + 1, qry + 1 + q, [&](auto x, auto y) { return x.t < y.t; });
build(1, 1, n);
// for(int j = 1; j <= n; ++j) cout << ask(1, 1, n, j, j) << ' '; cout << '\n';
int now = 0;
while(now < q && qry[now + 1].t == -1) ++now;
for(int i = 0; i <= m; ++i) {
modify(1, 1, n, 1, op[i].l - 1, 0);
// cout << t[12].sum3 << '\n';
modify(1, 1, n, op[i].l, op[i].r, op[i].x);
// cout << t[12].sum3 << '\n';
modify(1, 1, n, op[i].r + 1, n, 0);
// cout << i << ' ' << op[i].r << ' ' << t[12].sum3 << '\n';
// for(int j = 1; j <= n; ++j) cout << ask(1, 1, n, j, j) << ' '; cout << '\n';
while(now < q && qry[now + 1].t <= i) {
++now;
if(qry[now].sgn == 1) ans[qry[now].id] = (ans[qry[now].id] + ask(1, 1, n, qry[now].l, qry[now].r)) % mod;
else ans[qry[now].id] = (ans[qry[now].id] - ask(1, 1, n, qry[now].l, qry[now].r) + mod) % mod;
}
}
for(int i = 1; i <= q / 2; ++i) cout << ans[i] << '\n';
}
signed main() {
// freopen("e.in", "r", stdin);
// freopen("e1.out", "w", stdout);
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
for(int i = 0; i < 4; ++i) I.x[i][i] = 1;
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 20224kb
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: 0ms
memory: 21908kb
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: 21184kb
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:
53866943 279478 881641276 841999497 56195989 90706154 270683312 450935095 835603222 800743867 864720046 480690173 811171254 562745155 152266362 473901758 263118069 124037336 615492791 40336593 983965002 848340298 539877921 440406648 553728064 642626534 467720280 498489170 369560740 727001497 7806747...
result:
wrong answer 1st numbers differ - expected: '400489222', found: '53866943'