QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#41247#1831. BruteforceAntistarWA 3ms9712kbC++203.9kb2022-07-29 09:54:532022-07-29 09:54:54

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-29 09:54:54]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9712kb
  • [2022-07-29 09:54:53]
  • 提交

answer


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;
int n, k, w, a[100005], b[200005], rk[200005], id[200005], POS[100005], X[100005], N, C[8][8];

struct query {
  int op, p, x;
} que[00005];

int indec;

 int qpow(int x, int y, int mod) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = res * x % mod;
    x = x * x % mod, y >>= 1;
  }
  return res;
}

struct seg {
  int l, r, add;
  int smod[5][6], sum[6];
} t[600005];

void build(int now, int l, int r) {
  t[now].l = l, t[now].r = r;
  for (int i = 0; i < 5; i++)
    for (int j = 0; j <= 5; j++)
      t[now].smod[i][j] = t[now].sum[j] = 0;
  if (l == r)
    return;
  int mid = (l + r) / 2;
  build(now * 2, l, mid), build(now * 2 + 1, mid + 1, r);
}

void shift(int now, int x) {
  t[now].add += x;
  for (int i = 5; i >= 1; i--) {
    for (int j = i - 1; j >= 0; j--)
      t[now].sum[i] += t[now].sum[j] * qpow(x, i - j, mod) % mod * C[i][j];
    t[now].sum[i] %= mod;
  }
  int qwq[5][6];
  for (int i = 0; i < 5; i++)
    for (int j = 0; j <= 5; j++)
      qwq[i][j] = t[now].smod[(i + x % w + w) % w][j];
  for (int i = 0; i < 5; i++)
    for (int j = 0; j <= 5; j++)
      t[now].smod[i][j] = qwq[i][j];
}

inline void pushdown(int now) {
  if (t[now].add) {
    shift(now * 2, t[now].add);
    shift(now * 2 + 1, t[now].add);
    t[now].add = 0;
  }
}

inline void pushup(int now) {
  for (int i = 0; i < 5; i++)
    for (int j = 0; j <= 5; j++)
      t[now].smod[i][j] = t[now * 2].smod[i][j] + t[now * 2 + 1].smod[i][j];
  for (int j = 0; j <= 5; j++)
    t[now].sum[j] = (t[now * 2].sum[j] + t[now * 2 + 1].sum[j]) % mod;
}

inline void modify_rk(int now, int l, int r, int x) {
  if (t[now].l == l && t[now].r == r) {
    shift(now, x);
    return;
  }
  pushdown(now);
  if (t[now * 2].r >= r)
    modify_rk(now * 2, l, r, x);
  else if (t[now * 2 + 1].l <= l)
    modify_rk(now * 2 + 1, l, r, x);
  else
    modify_rk(now * 2, l, t[now * 2].r, x), modify_rk(now * 2 + 1, t[now * 2 + 1].l, r, x);
  pushup(now);
}

inline void modify_eb(int now, int p, int x) {
  if (t[now].l == t[now].r) {
    t[now].sum[0] = x;
    for (int i = 1; i <= 5; i++)
      t[now].sum[i] = t[now].sum[i - 1] * t[now].add % mod;
    for (int k = 0; k < 5; k++) {
      t[now].smod[k][0] = x % w;
      for (int i = 1; i <= 5; i++)
        t[now].smod[k][i] = t[now].smod[k][i - 1] * (t[now].add + k) % w;
    }
    return;
  }
  pushdown(now);
  if (t[now * 2].r >= p)
    modify_eb(now * 2, p, x);
  else
    modify_eb(now * 2 + 1, p, x);
  pushup(now);
}

inline int query_sum() {
  return t[1].sum[k];
}

inline int query_mod() {
  return t[1].smod[0][k];
}

inline int inv(int x) {
  return qpow(x, mod - 2, mod);
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k >> w;
  id[0] = 1;
  for (int i = 0; i <= 5; i++) {
    C[i][0] = C[i][i] = 1;
    for (int j = 1; j < i; j++)
      C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    ++id[a[i] + 1];
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> POS[i] >> X[i];
    ++id[X[i] + 1];
  }
  for (int i = 1; i <= 100001; i++)
    id[i] += id[i - 1];
  N = id[100001];
  build(1, 1, N);
  for (int i = 1; i <= n; i++)
    que[++indec] = {1, ++id[a[i]], a[i]};
  for (int i = 1; i <= q; i++) {
    que[++indec] = {2, id[a[POS[i]]]--, a[POS[i]]};
    que[++indec] = {1, ++id[X[i]], X[i]};
    a[POS[i]] = X[i];
    que[++indec] = {3, 0, 0};
  }
  for (int i = 1; i <= indec; i++) {
    if (que[i].op == 1) {
      modify_rk(1, que[i].p, N, 1);
      modify_eb(1, que[i].p, que[i].x);
    }
    else if (que[i].op == 2) {
      modify_rk(1, que[i].p, N, -1);
      modify_eb(1, que[i].p, 0);
    }
    else
      cout << ((query_sum() - query_mod()) % mod * inv(w) % mod + mod) % mod << "\n";
  }
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 9712kb

input:

3 1 1
2 2 8
2
2 5
3 6

output:

36
30

result:

ok 2 number(s): "36 30"

Test #2:

score: -100
Wrong Answer
time: 3ms
memory: 7752kb

input:

4 2 2
1 3 3 7
4
1 1
2 4
3 8
4 8

output:

49
80
499122209
499122209
499122209
499122209

result:

wrong answer 1st numbers differ - expected: '75', found: '49'