QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#721000 | #6435. Paimon Segment Tree | wenqizhi | WA | 4ms | 32980kb | C++20 | 5.3kb | 2024-11-07 14:56:27 | 2024-11-07 14:56:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
int read()
{
int x = 0; bool f = false; char c = getchar();
while(c < '0' || c > '9') f |= (c == '-'), c = getchar();
while(c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c & 15), c = getchar();
return f ? -x : x;
}
const ll mod = 1e9 + 7;
ll qpow(ll a, ll b, ll mod)
{
ll ans = 1;
while(b)
{
if(b & 1) ans = ans * a % mod;
b >>= 1;
a = a * a % mod;
}
return ans;
}
const int N = 5e4 + 5;
int n, m, Q;
ll a[N], ans[N];
struct modify{ int l, r, x; }op[N];
struct node{ int id, type, l, r; };
vector<node> q[N];
ll add(ll a, ll b){ return (a + b >= mod) ? (a + b - mod) : (a + b); }
ll del(ll a, ll b){ return (a - b < 0) ? (a - b + mod) : (a - b); }
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
ll sum[N << 2][4];
struct Matrix
{
ll c[4][4];
Matrix(){ memset(c, 0, sizeof(c)); }
Matrix friend operator * (Matrix a, Matrix b)
{
Matrix c;
for(int i = 0; i < 4; ++i)
for(int k = 0; k < 4; ++k)
for(int j = 0; j < 4; ++j)
c.c[i][j] = (c.c[i][j] + a.c[i][k] * b.c[k][j]) % mod;
return c;
}
void clear()
{
for(int i = 0; i < 4; ++i)
for(int j = 0; j < 4; ++j)
c[i][j] = 0;
}
void init()
{
for(int i = 0; i < 4; ++i) c[i][i] = 1;
}
}lazy[N << 2], temp;
void pushup(int k)
{
for(int i = 0; i < 4; ++i)
sum[k][i] = add(sum[ls(k)][i], sum[rs(k)][i]);
}
void mul(int K, Matrix &t)
{
ll a[4] = {0, 0, 0, 0};
for(int k = 0; k < 4; ++k)
for(int j = 0; j < 4; ++j)
a[j] = (a[j] + sum[K][k] * t.c[k][j]) % mod;
for(int i = 0; i < 4; ++i) sum[K][i] = a[i];
}
void pushdown(int k)
{
mul(ls(k), lazy[k]), mul(rs(k), lazy[k]);
lazy[ls(k)] = lazy[ls(k)] * lazy[k];
lazy[rs(k)] = lazy[rs(k)] * lazy[k];
lazy[k].clear(), lazy[k].init();
}
void build(int k, int l, int r)
{
// printf("k = %d, l = %d, r = %d\n", k, l, r);
lazy[k].init();
if(l == r)
{
sum[k][0] = 1;
sum[k][1] = a[l];
sum[k][2] = a[l] * a[l] % mod;
sum[k][3] = sum[k][2];
return ;
}
int mid = (l + r) >> 1;
build(ls(k), l, mid), build(rs(k), mid + 1, r);
pushup(k);
}
ll query(int k, int l, int r, int L, int R)
{
if(L <= l && r <= R) return sum[k][3];
pushdown(k);
int mid = (l + r) >> 1;
if(R <= mid) return query(ls(k), l, mid, L, R);
if(L > mid) return query(rs(k), mid + 1, r, L, R);
return add(query(ls(k), l, mid, L, R), query(rs(k), mid + 1, r, L, R));
}
void update(int k, int l, int r, int L, int R)
{
if(L <= l && r <= R)
{
mul(k, temp);
lazy[k] = lazy[k] * temp;
return ;
}
pushdown(k);
int mid = (l + r) >> 1;
if(L <= mid) update(ls(k), l, mid, L, R);
if(R > mid) update(rs(k), mid + 1, r, L, R);
pushup(k);
}
void down(int k, int l, int r)
{
if(l == r) return ;
pushdown(k);
int mid = (l + r) >> 1;
down(ls(k), l, mid), down(rs(k), mid + 1, r);
}
int main()
{
n = read(), m = read(), Q = read();
for(int i = 1; i <= n; ++i) a[i] = read();
build(1, 1, n);
for(int i = 1; i <= m; ++i)
{
op[i].l = read();
op[i].r = read();
op[i].x = read();
}
for(int i = 1; i <= Q; ++i)
{
int l = read(), r = read(), x = read(), y = read();
if(x >= 1) q[x - 1].emplace_back((node){i, -1, l, r});
q[y].emplace_back((node){i, 1, l, r});
}
// printf("t = 0\n");
for(auto [id, type, l, r] : q[0])
{
// printf("query(%d, %d) = %lld\n", l, r, query(1, 1, n, l, r));
ans[id] = (ans[id] + query(1, 1, n, l, r) * type + mod) % mod;
}
for(int t = 1; t <= m; ++t)
{
if(op[t].l > 1)
{
temp.clear();
temp.c[0][0] = temp.c[1][1] = temp.c[2][2] = temp.c[3][3] = temp.c[2][3] = 1;
update(1, 1, n, 1, op[t].l - 1);
}
if(op[t].r < n)
{
temp.clear();
temp.c[0][0] = temp.c[1][1] = temp.c[2][2] = temp.c[3][3] = temp.c[2][3] = 1;
update(1, 1, n, op[t].r + 1, n);
}
temp.clear();
temp.c[0][0] = temp.c[1][1] = temp.c[2][2] = temp.c[3][3] = temp.c[2][3] = 1;
temp.c[0][1] = op[t].x , temp.c[1][2] = temp.c[1][3] = add(op[t].x , op[t].x );
temp.c[0][2] = temp.c[0][3] = 1ll * op[t].x * op[t].x % mod;
update(1, 1, n, op[t].l , op[t].r );
// printf("t = %d\n", t);
// printf("query(2, 2) = %lld\n", query(1, 1, n, 2, 2));
// for(int i = 0; i < 4; ++i) printf("%d ", sum[5][i]);
// printf("\n");
// down(1, 1, n);
// for(int i = 0; i < 4; ++i)
// {
// for(int j = 0; j < 4; )
// }
for(auto [id, type, l, r] : q[t])
{
// printf("query(%d, %d) = %lld\n", l, r, query(1, 1, n, l, r));
ans[id] = (ans[id] + query(1, 1, n, l, r) * type + mod) % mod;
}
}
for(int i = 1; i <= Q; ++i) printf("%lld\n", ans[i]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 32124kb
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: 32432kb
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: 4ms
memory: 32980kb
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:
400489222 480617351 531108525 254983761 446689548 764223236 142229431 307405789 -960182726 66225912 247029353 46506707 529135498 578008236 201809860 -325921563 746060191 171471121 -277528534 657196163 -138448169 606551808 360903956 401221326 -232428092 669762004 163759234 141144218 579174939 2765571...
result:
wrong answer 9th numbers differ - expected: '39817281', found: '-960182726'