QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#14761#1831. Bruteforcepnm1384WA 339ms58988kbC++173.3kb2021-10-13 04:23:202022-05-17 01:00:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-17 01:00:26]
  • 评测
  • 测评结果:WA
  • 用时:339ms
  • 内存:58988kb
  • [2021-10-13 04:23:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
int mod = 998244353;

#define F first
#define S second

const int N = 2e5 + 500, W = 7;
pair<int, int> a[N];
int fac[N], inv[N], pre[N][W][W], ans1[N << 2][W], cnt[N << 2], ans2[N << 2][W], poww[N][W], md[N][W];
pair<int, int> bad[N], que[N];
int sz = 0;
int n, k, w;

inline void mkey(int& x)
{
	while (x >= mod) x -= mod;
	while (x < 0) x += mod;
	return;
}

int pw(int x, int y)
{
	int ans = 1;
	for (; y; y >>= 1, x = 1ll * x * x % mod)
	{
		if (y & 1) ans = 1ll * ans * x % mod;
	}
	return ans;
}

inline int C(int n, int k)
{
	if (k < 0 || k > n) return 0;
	if (k == 0) return 1;
	return 1ll * fac[n] * inv[k] % mod * inv[n - k] % mod;
}

void change(int ind, int f, int u = 1, int s = 0, int e = sz)
{
	if (e - s < 2)
	{
		if (f == -1)
		{
			for (int i = 0; i < w; i++) ans1[u][i] = 0;
			for (int i = 0; i <= k; i++) ans2[u][i] = 0;
			cnt[u] = 0;
			return;
		}
		cnt[u] = 1;
		for (int i = 0; i < w; i++)
		{
			ans1[u][i] = md[bad[s].F][w] * poww[i][k] % w;
		}
	//	cout << "  " << s + 1 << "  " << e << '\n';
		for (int i = 0; i <= k; i++)
		{
			ans2[u][i] = bad[s].F;
		//	cout << "                     " << i << "  " << ans2[u][i] << '\n';
		}
		return;
	}
	int lc = u << 1, rc = lc | 1, mid = (s + e) >> 1;
	if (ind < mid)
		change(ind, f, lc, s, mid);
	else
		change(ind, f, rc, mid, e);

	cnt[u] = cnt[lc] + cnt[rc];
	for (int i = 0; i < w; i++)
	{
		mkey(ans1[u][i] = ans1[lc][i] + ans1[rc][md[i + cnt[lc]][w]]);
	}
//	cout << "  " << s + 1 << "  " << e << '\n';
	for (int i = 0; i <= k; i++)
	{
		mkey(ans2[u][i] = ans2[lc][i]);
		for (int j = 0; j <= i; j++)
		{
			mkey(ans2[u][i] += 1ll * pre[cnt[lc]][j][i] * ans2[rc][j] % mod);
		}
//		cout << "             " << i << " " << ans2[u][i] << '\n';
	}
	return;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	fac[0] = 1;
	for (int i = 1; i < N; i++) fac[i] = 1ll * i * fac[i - 1] % mod;
	inv[N - 1] = pw(fac[N - 1], mod - 2);
	for (int i = N - 2; i > -1; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % mod;
	cin >> n >> k >> w;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		a[i] = {x, i};
		bad[sz++] = {x, i};
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int pos, x;
		cin >> pos >> x;
		pos--;
		que[i] = {pos, x};
		bad[sz++] = {x, i + n};
	}
	sort(bad, bad + sz);
//	for (int i = 0; i < sz; i++) cout << "                      " << bad[i].F << "   " << bad[i].S << '\n';
	
	for (int x = 0; x < N; x++)
	{
		for (int i = 0; i < W; i++)
		{
			for (int j = i; j < W; j++)
			{
				pre[x][i][j] = 1ll * pw(x, j - i) * C(j, i) % mod;
			}
			poww[x][i] = pw(x, i);
			if (i != 0) md[x][i] = x % i;
		}
	}
	for (int i = 0; i < n; i++)
	{
		int ind = lower_bound(bad, bad + sz, a[i]) - bad;
		change(ind, 1);
	}
//	cout << ans2[1][1] << '\n';
	for (int jj = 0; jj < q; jj++)
	{
		int pos = que[jj].F, x = que[jj].S;
		int ind = lower_bound(bad, bad + sz, a[pos]) - bad;
		change(ind, -1);
		ind = lower_bound(bad, bad + sz, make_pair(x, n + jj)) - bad;
		change(ind, 1);
		a[pos] = bad[ind];
		int ans = 0;
		mkey(ans = ans2[1][k] - ans1[1][md[1][w]]);
		ans = 1ll * ans * inv[w] % mod;
		cout << ans << '\n';
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 323ms
memory: 58792kb

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: 0
Accepted
time: 298ms
memory: 57800kb

input:

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

output:

75
80
103
108

result:

ok 4 number(s): "75 80 103 108"

Test #3:

score: 0
Accepted
time: 316ms
memory: 58988kb

input:

10 1 1
16251 28898 58179 69362 48663 81443 34949 87167 16552 58931
10
6 89124
8 27159
4 7332
1 15852
9 67405
7 19413
10 97472
7 31114
6 31847
5 43794

output:

3511390
3107346
2780002
2779204
3079414
3018965
3365708
3406982
2970195
2936112

result:

ok 10 numbers

Test #4:

score: 0
Accepted
time: 329ms
memory: 57948kb

input:

100 2 2
44625 87890 57662 73552 89172 64466 22834 24089 60132 5187 88984 19022 67559 53954 42114 19018 80035 3367 50518 15479 72359 15452 38886 5945 34974 86214 16805 71388 48981 45377 34170 61384 88881 29453 94738 94669 56746 80508 79155 94505 82745 38134 41769 2032 23186 5636 39727 54400 86133 497...

output:

81216962
152846115
156547587
163221145
293598979
178882623
92185541
202208317
181562234
200670345
213033267
262881364
247600647
301317991
271334928
261885869
261690216
247578015
236998290
291971331
293746018
424418987
402413699
300515771
300819876
344295103
391424353
392633865
361623113
355154190
47...

result:

ok 100 numbers

Test #5:

score: -100
Wrong Answer
time: 339ms
memory: 58876kb

input:

1000 5 5
67444 21858 17070 50937 22108 62205 2999 96284 84111 16255 69173 11611 84406 28349 95817 86160 87289 19642 22706 44359 31899 36187 15946 86429 23120 65928 81187 32204 37790 18497 52182 23455 59579 78480 45277 57706 60123 99315 19014 72404 35420 14632 12210 38628 1729 18606 23941 96652 80784...

output:

517829800
221243906
710855097
532938989
438288383
486385213
501746789
715476968
443279817
43231023
911168079
901894235
765993147
922225530
636712545
10988676
841886650
75648127
469161238
25375797
530124120
636948972
505220059
28525270
919459953
80241041
432411922
663072562
828945344
258346987
161095...

result:

wrong answer 1st numbers differ - expected: '448982964', found: '517829800'