QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694103#6435. Paimon Segment TreeRegistrationError#WA 1ms7964kbC++204.5kb2024-10-31 17:16:352024-10-31 17:16:36

Judging History

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

  • [2024-10-31 17:16:36]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7964kb
  • [2024-10-31 17:16:35]
  • 提交

answer

#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define sz(a) (int) (a).size()
#define int long long
using namespace std;

const int N = 5e4 + 11;
const int MOD = 1e9 + 7;
int a[N], ans[N];

struct update{
    int l, r, t, x;
};

struct query{
    int t, l, r, mul, id;
};

void chadd(int& x, int y) {
    y %= MOD;
    x += y; x %= MOD;
}

struct node{
    int t, x[3], cx[3];
    node() = default;
    node(int v) {
        t = 0;
        x[0] = 1; x[1] = v; x[2] = v * v % MOD;
        cx[0] = cx[1] = cx[2] = 0;
    }

    friend node operator+ (const node& a, const node& b) {
        // assert(a.t == b.t);
        node c;
        c.t = a.t;
        for (int i = 0; i < 3; i++) {
            c.x[i] = (a.x[i] + b.x[i]) % MOD;
            c.cx[i] = (a.cx[i] + b.cx[i]) % MOD;
        }
        return c;
    }

    int get_ans(int T) {
        // cout << "x[] => ";
        // for (int i = 0; i < 3; i++) {
        //     cout << x[i] << ' ';
        // }
        // cout << endl;
        // cout << "cx[] => ";
        // for (int i = 0; i < 3; i++) {
        //     cout << cx[i] << ' ';
        // }
        // cout << endl;
        return (x[2] * T + cx[2]) % MOD;
    }
};

struct tag{
    int t, x, cx[3];
    tag() = default;
    tag(int t, int v) {
        tag::t = t;
        x = v;
        cx[0] = cx[1] = cx[2] = 0;
    }
};

int n, m, q;
node T[N << 2];
tag flag[N << 2];

void add_slope(int t2, int& cx, int& x, int add) {
    chadd(cx, -t2 * add);
    chadd(x, add);
}

void operator+= (node& V, const tag& f) {
    int dt = f.t - V.t;
    int ox0 = V.x[0], ox1 = V.x[1];
    add_slope(f.t, V.cx[1], V.x[1], ox0 * f.x);
    add_slope(f.t, V.cx[2], V.x[2], ox0 * f.x % MOD * f.x % MOD + ox1 * f.x * 2 % MOD);
    chadd(V.cx[1], ox0 * f.cx[1]);
    chadd(V.cx[2], ox0 * f.cx[2] + ox1 * f.cx[1] * 2 % MOD);
    V.t += dt;
}

void operator+= (tag& f, const tag& g) {
    for (int i = 0; i < 3; i++) {
        chadd(f.cx[i], g.cx[i]);
    }
    int dt = g.t - f.t;
    chadd(f.cx[1], -g.x * dt);
    chadd(f.cx[2], (-f.x * g.x * 2 - g.x * g.x) % MOD * dt);
    chadd(f.x, g.x);
}

void push(int t, int v) {
    flag[v] += tag(t, 0);
    T[v * 2 + 1] += flag[v];
    T[v * 2 + 2] += flag[v];
    flag[v * 2 + 1] += flag[v];
    flag[v * 2 + 2] += flag[v];
    flag[v] = tag(t, 0);
}

void build(int v = 0, int l = 1, int r = n) {
    if (l == r) {
        T[v] = node(a[l]);
    } else {
        int m = (l + r) / 2;
        build(v * 2 + 1, l, m);
        build(v * 2 + 2, m + 1, r);
        T[v] = T[v * 2 + 1] + T[v * 2 + 2];
    }
}

void upd(int t, int ql, int qr, int qx, int v = 0, int l = 1, int r = n) {
    if (qr < l || r < ql) return;
    if (ql <= l && r <= qr) {
        T[v] += tag(t, qx);
        flag[v] += tag(t, qx);
    } else {
        int m = (l + r) / 2; push(t, v);
        upd(t, ql, qr, qx, v * 2 + 1, l, m);
        upd(t, ql, qr, qx, v * 2 + 2, m + 1, r);
        T[v] = T[v * 2 + 1] + T[v * 2 + 2];
    }
}

int qry(int t, int ql, int qr, int v = 0, int l = 1, int r = n) {
    if (qr < l || r < ql) return 0;
    if (ql <= l && r <= qr) {
        return T[v].get_ans(t);
    } else {
        int m = (l + r) / 2; push(t, v);
        int qa = qry(t, ql, qr, v * 2 + 1, l, m);
        int qb = qry(t, ql, qr, v * 2 + 2, m + 1, r);
        return (qa + qb) % MOD;
    }
}

void solve() {
    cin >> n >> m >> q;
    for (int i = 1; i <= n; i++) cin >> a[i];
    vector<update> U; vector<query> Q;
    for (int i = 0; i < m; i++) {
        int l, r, x; cin >> l >> r >> x;
        U.push_back({l, r, i, x});
    }
    for (int i = 0; i < q; i++) {
        int l, r, x, y; cin >> l >> r >> x >> y;
        Q.push_back({y + 1, l, r, 1, i});
        Q.push_back({x, l, r, -1, i});
    }
    sort(all(Q), [] (auto a, auto b) {
        return a.t < b.t;
    });
    int qi = 0;
    for (int i = 0; i <= m + 1; i++) {
        while (qi < Q.size() && Q[qi].t == i) {
            auto& q = Q[qi++];
            ans[q.id] += q.mul * qry(q.t, q.l, q.r);
        }
        if (i == 0) {
            build();
        } else if (1 <= i && i <= m) {
            auto& u = U[i - 1];
            upd(i, u.l, u.r, u.x);
        }
    }
    for (int i = 0; i < q; i++) {
        int rans = (ans[i] % MOD + MOD) % MOD;
        cout << rans << '\n';
    }
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(false);

    int t = 1; // cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 7964kb

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: 1ms
memory: 3644kb

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:

8322961
799819782
808548075
856139891
257468122
299357332
736215935
282714972
911758043
969855561
984350836
726935687
946770352
935391607
29693136
577523836
557841192
485149396
663625131
426526289
430459098
415815364
818374786
333669449
467851094
662745050
485272951
92289320
948870254
295504804
4771...

result:

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