QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#719133#6435. Paimon Segment TreeFUCKUCUPWA 5ms21456kbC++204.9kb2024-11-06 22:39:542024-11-06 22:39:58

Judging History

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

  • [2024-11-06 22:39:58]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:21456kb
  • [2024-11-06 22:39:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn = 50010, mod = 1e9 + 7;
int n, m, q, a[maxn], ans[maxn];
struct operation { int l, r, x; }op[maxn];
struct query { int l, r, t, sgn, id; }qry[maxn << 1];
struct matrix {
    matrix() { memset(x, 0, sizeof x); }
    int x[4][4];
}I;
inline bool operator != (matrix &a, matrix &b) {
  for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) if(a.x[i][j] != b.x[i][j]) return true;
  return false;
}
inline matrix operator * (matrix &a, 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.x[i][j] = (c.x[i][j] + 1ll * a.x[i][k] * b.x[k][j]) % mod;
  }
  return c;
}
struct node {
    int sum3, sum2, sum, len;
    matrix tag;
}t[maxn << 2];
inline void update(int d) {
  t[d].sum3 = (t[d << 1].sum3 + t[d << 1 | 1].sum3) % mod;
  t[d].sum2 = (t[d << 1].sum2 + t[d << 1 | 1].sum2) % mod;
  t[d].sum = (t[d << 1].sum + t[d << 1 | 1].sum) % mod;
}
inline void calc(int &a, int &b, int &c, int &d, matrix &mt) {
  int vec[4] = {a, b, c, d}, res[4] = {0, 0, 0, 0};
  for(int i = 0; i < 4; ++i) for(int j = 0; j < 4; ++j) res[i] = (res[i] + 1ll * vec[j] * mt.x[i][j]) % mod;
  a = res[0], b = res[1], c = res[2], d = res[3];
}
inline void pushdown(int d) {
  calc(t[d << 1].sum3, t[d << 1].sum2, t[d << 1].sum, t[d << 1].len, t[d].tag);
  calc(t[d << 1 | 1].sum3, t[d << 1 | 1].sum2, t[d << 1 | 1].sum, t[d << 1 | 1].len, t[d].tag);
  t[d << 1].tag = t[d << 1].tag * t[d].tag;
  t[d << 1 | 1].tag = t[d << 1 | 1].tag * t[d].tag;
  t[d].tag = I;
}
void build(int d, int l, int r) {
  t[d].tag = I, t[d].len = r - l + 1;
//  cout << l << ' ' << r << ' ' << t[d].len << '\n';
  if(l == r) {
    t[d].sum3 = 0;
    t[d].sum2 = 1ll * a[l] * a[l] % mod;
    t[d].sum = a[l];
    return;
  }
  int md = l + r >> 1;
  build(d << 1, l, md), build(d << 1 | 1, md + 1, r);
  update(d);
}
void modify(int d, int l, int r, int dl, int dr, int x) {
  if(dl > dr) return;
  if(dl <= l && r <= dr) {
    matrix tmp;
    tmp.x[0][0] = tmp.x[0][1] = 1, tmp.x[0][2] = 2ll * x % mod, tmp.x[0][3] = 1ll * x * x % mod;
    tmp.x[1][1] = 1, tmp.x[1][2] = 2ll * x % mod, tmp.x[1][3] = 1ll * x * x % mod;
    tmp.x[2][2] = 1, tmp.x[2][3] = x;
    tmp.x[3][3] = 1;
    t[d].tag = tmp * t[d].tag;
    t[d].sum2 = (t[d].sum2 + 2ll * t[d].sum * x % mod + 1ll * x * x % mod * (r - l + 1) % mod) % mod;
    t[d].sum = (t[d].sum + 1ll * (r - l + 1) * x % mod) % mod;
    t[d].sum3 = (t[d].sum3 + t[d].sum2) % mod;
//    cout << l << ' ' << r << ' ' << t[d].sum3 << ' ' << t[d].sum2 << ' ' << t[d].sum << '\n';
    return;
  }
  if(t[d].tag != I) pushdown(d);
  int md = l + r >> 1;
  if(dl <= md) modify(d << 1, l, md, dl, dr, x);
  if(dr > md) modify(d << 1 | 1, md + 1, r, dl, dr, x);
  update(d);
}
int ask(int d, int l, int r, int dl, int dr) {
//  cout << d << ' ' << l << ' ' << r << '\n';
  if(dl <= l && r <= dr) return t[d].sum3;
  if(t[d].tag != I) pushdown(d);
  int md = l + r >> 1, ans = 0;
  if(dl <= md) ans = ask(d << 1, l, md, dl, dr);
  if(dr > md) ans = (ans + ask(d << 1 | 1, md + 1, r, dl, dr)) % mod;
  return ans;
}
int ask2(int d, int l, int r, int dl, int dr) {
//  cout << d << ' ' << l << ' ' << r << '\n';
  if(dl <= l && r <= dr) return t[d].sum2;
  if(t[d].tag != I) pushdown(d);
  int md = l + r >> 1, ans = 0;
  if(dl <= md) ans = ask2(d << 1, l, md, dl, dr);
  if(dr > md) ans = (ans + ask2(d << 1 | 1, md + 1, r, dl, dr)) % mod;
  return ans;
}
inline void solve() {
  cin >> n >> m >> q;
  for(int i = 1; i <= n; ++i) cin >> a[i], a[i] = (a[i] + mod) % mod;
  op[0] = {1, n, 0};
  for(int i = 1; i <= m; ++i) cin >> op[i].l >> op[i].r >> op[i].x, op[i].x = (op[i].x + mod) % mod;
  for(int i = 1; i <= q; ++i) {
    int l, r, x, y;
    cin >> l >> r >> x >> y;
    qry[i] = {l, r, x - 1, -1, i}, qry[i + q] = {l, r, y, 1, i};
  }
  q <<= 1, sort(qry + 1, qry + 1 + q, [&](auto x, auto y) { return x.t < y.t; });
  build(1, 1, n);
//  for(int j = 1; j <= n; ++j) cout << ask(1, 1, n, j, j) << ' '; cout << '\n';
  int now = 0;
  while(now < q && qry[now + 1].t == -1) ++now;
  for(int i = 0; i <= m; ++i) {
    modify(1, 1, n, 1, op[i].l - 1, 0);
    modify(1, 1, n, op[i].l, op[i].r, op[i].x);
    modify(1, 1, n, op[i].r + 1, n, 0);
//    for(int j = 1; j <= n; ++j) cout << ask(1, 1, n, j, j) << ' '; cout << '\n';
    while(now < q && qry[now + 1].t <= i) {
      ++now;
      if(qry[now].sgn == 1) ans[qry[now].id] = (ans[qry[now].id] + ask(1, 1, n, qry[now].l, qry[now].r)) % mod;
      else ans[qry[now].id] = (ans[qry[now].id] - ask(1, 1, n, qry[now].l, qry[now].r) + mod) % mod;
    }
  }
  for(int i = 1; i <= q / 2; ++i) cout << ans[i] << '\n';
}
signed main() {
//	freopen("e.in", "r", stdin);
//	freopen("e1.out", "w", stdout);
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  for(int i = 0; i < 4; ++i) I.x[i][i] = 1;
  solve();
  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 5ms
memory: 21264kb

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

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

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:

598274137
216047279
227840217
924161040
401200874
512520722
389200838
155583656
306814597
838091876
892737145
480690173
747595054
427386659
365225281
577231676
312392709
96086750
132125252
129557277
788224590
891101987
208453584
818693008
810885359
402958198
763091408
496361146
805214449
742215606
3...

result:

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