QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#655148#6437. Paimon's TreellleiRE 0ms0kbC++203.9kb2024-10-19 00:50:092024-10-19 00:50:10

Judging History

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

  • [2024-10-19 00:50:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-19 00:50:09]
  • 提交

answer

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,tune=native,popcnt,lzcnt,abm,bmi,bmi2,fma")
using namespace std;
using LL = long long;
const LL mod = 1e9 + 7;
const int N = 5e4 + 5;
int n, m, q;
int a[N];
struct Matrix {
    LL mt[4][4];
    Matrix() : mt{} {}
    Matrix(int b, int len) : mt{} {
        mt[0][0] = 1;
        mt[0][1] = b * 1LL * len % mod, mt[1][1] = 1;
        mt[0][2] = b * 1ll * b % mod * len % 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;
Matrix operator*(const Matrix &a, const Matrix &b) {
    Matrix c = Matrix();
    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] = (a.mt[i][k] * 1LL * b.mt[k][j] + c.mt[i][j]) % mod;
        }
    return c;
}
Matrix operator+(const Matrix &a, const Matrix &b) {
    Matrix c = Matrix();
    for (int i = 0; i < 4; i++)
        for (int j = 0; j < 4; j++) {
            c.mt[i][j] = (a.mt[i][j] + b.mt[i][j]) % mod;
        }
    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];
        tag[rt] = E;
        vis[rt << 1] = vis[rt << 1 | 1] = 1;
        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, 1);
        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];
}
LL 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];
LL 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] += query(l, r, 1, n, 1) * t.second.second;
            ans[t.second.first] %= mod;
        }
    }
    for (int i = 1; i <= q; i++)
        cout << (ans[i] % mod + mod) % mod << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

2
5
1 7 3 5 4
1 3
2 3
3 4
4 5
4 6
1
1000000000
1 2

output:


result: