QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#655794#6435. Paimon Segment TreellleiWA 3ms30344kbC++203.8kb2024-10-19 09:42:032024-10-19 09:42:04

Judging History

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

  • [2024-10-19 09:42:04]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:30344kb
  • [2024-10-19 09:42:03]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,tune=native")
using namespace std;
const int mod = 1e9 + 7;
const int N = 5e4 + 5;
int n, m, q;
int a[N];
struct Matrix {
    int mt[4][4];
    Matrix() : mt{} {}
    Matrix(int b) : mt{} {
        mt[0][0] = 1;
        mt[0][1] = b % mod, mt[1][1] = 1;
        mt[0][2] = b * 1ll * b % mod, mt[1][2] = 2 * 1ll * b % mod, mt[2][2] = 1;
        mt[0][3] = mt[0][2], mt[1][3] = mt[1][2], mt[2][3] = mt[3][3] = 1;
    }
} E;
int md(int x) { return x >= mod ? x - mod : x; }
Matrix operator*(const Matrix &a, const 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.mt[i][j] = md(a.mt[i][k] * 1LL * b.mt[k][j] % mod + c.mt[i][j]);
        }
    return c;
}
Matrix operator+(const Matrix &a, const Matrix &b) {
    Matrix c;
    for (int i = 0; i < 4; i++)
        for (int j = 0; j < 4; j++) {
            c.mt[i][j] = md(a.mt[i][j] + b.mt[i][j]);
        }
    return c;
}
Matrix tag[N << 2];
Matrix sum[N << 2];
int vis[N << 2];
void pushdown(int rt) {
    if (vis[rt]) {
        sum[rt << 1] = sum[rt << 1] * tag[rt];
        sum[rt << 1 | 1] = sum[rt << 1 | 1] * tag[rt];
        tag[rt << 1] = tag[rt << 1] * tag[rt];
        tag[rt << 1 | 1] = tag[rt << 1 | 1] * tag[rt];
        vis[rt << 1] = 1;
        vis[rt << 1 | 1] = 1;
        tag[rt] = E;
        vis[rt] = 0;
    }
}
void update(int L, int R, int l, int r, int rt, int b) {
    if (L <= l && r <= R) {
        Matrix tmp = Matrix(b);
        tag[rt] = tag[rt] * tmp;
        sum[rt] = sum[rt] * tmp;
        vis[rt] = 1;
        return;
    }
    pushdown(rt);
    int mid = l + r >> 1;
    if (L <= mid)
        update(L, R, l, mid, rt << 1, b);
    if (R > mid)
        update(L, R, mid + 1, r, rt << 1 | 1, b);
    sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
int query(int L, int R, int l, int r, int rt) {
    if (L <= l && r <= R)
        return sum[rt].mt[0][3];
    pushdown(rt);
    int mid = l + r >> 1, ans = 0;
    if (L <= mid)
        ans = (ans + query(L, R, l, mid, rt << 1)) % mod;
    if (R > mid)
        ans = (ans + query(L, R, mid + 1, r, rt << 1 | 1)) % mod;
    return ans;
}
void build(int l, int r, int rt) {
    tag[rt] = E;
    if (l == r) {
        sum[rt] = E;
        return;
    }
    int mid = l + r >> 1;
    build(l, mid, rt << 1);
    build(mid + 1, r, rt << 1 | 1);
    sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
int L[N], R[N], W[N];
int ans[N];
vector<pair<pair<int, int>, pair<int, int>>> qr[N];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> n >> m >> q;
    for (int i = 0; i < 4; i++)
        E.mt[i][i] = 1;
    build(1, n, 1);
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        update(i, i, 1, n, 1, x);
    }
    for (int i = 1; i <= m; i++)
        cin >> L[i] >> R[i] >> W[i];
    for (int i = 1; i <= q; i++) {
        int l, r, x, y;
        cin >> l >> r >> x >> y;
        if (x >= 1)
            qr[x - 1].push_back({{l, r}, {i, -1}});
        qr[y].push_back({{l, r}, {i, 1}});
    }
    for (int i = 0; i <= m; i++) {

        if (i) {
            if (L[i] - 1 >= 1)
                update(1, L[i] - 1, 1, n, 1, 0);
            update(L[i], R[i], 1, n, 1, W[i]);
            if (R[i] + 1 <= n)
                update(R[i] + 1, n, 1, n, 1, 0);
        }
        for (auto t : qr[i]) {
            int l = t.first.first;
            int r = t.first.second;
            // cout << query(l, r, 1, n, 1) << ' ' << i << '%' << '\n';
            (ans[t.second.first] += 1ll * query(l, r, 1, n, 1) * t.second.second % mod) %= mod;
        }
    }
    for (int i = 1; i <= q; i++)
        cout << (ans[i] % mod + mod) % mod << '\n';
}

詳細信息

Test #1:

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

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: 29160kb

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: 0ms
memory: 30344kb

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
543371150
947145241
832295978
367030471
85911722
283066901
741707994
461388626
247029353
943672954
868972316
826774785
106450500
845850213
131983431
241316769
843252370
230593516
742051118
606551808
304153107
380683218
248765302
364906843
179755969
464984301
553101444
600397251
9...

result:

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