QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#693702 | #6434. Paimon Sorting | RegistrationError# | WA | 1ms | 7916kb | C++20 | 4.4kb | 2024-10-31 16:36:27 | 2024-10-31 16:36:27 |
Judging History
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 t1, 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 ox1 = V.x[1], ox0 = V.x[0];
add_slope(V.t, f.t, V.cx[1], V.x[1], ox0 * f.x);
add_slope(V.t, f.t, V.cx[2], V.x[2], ox0 * f.x % MOD * f.x % MOD + ox1 * f.x * 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], -f.x * dt);
chadd(f.cx[2], (-f.x * g.x * 2 - g.x * g.x) % MOD * dt);
chadd(f.x, g.x);
chadd(f.t, dt);
}
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: 0
Wrong Answer
time: 1ms
memory: 7916kb
input:
3 5 2 3 2 1 5 3 1 2 3 1 1
output:
0 0
result:
wrong answer 1st lines differ - expected: '0 2 3 5 7', found: '0'