QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#14495#1831. BruteforcewqliWA 37ms29888kbC++173.2kb2021-10-07 17:29:222022-05-17 00:35:17

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 00:35:17]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:29888kb
  • [2021-10-07 17:29:22]
  • 提交

answer

#include <algorithm>
#include <numeric>
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 8e5+10;
const int mod = 998244353;

ll bpow(ll x, ll y)
{
	ll ans = 1;
	while(y > 0)
	{
		if(y & 1)
			ans = ans * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return ans;
}

struct idfer
{
	ll cont; // content
	bool ogarr; // 0 -> arr, 1 -> queries
	int ogidx;
	int validx;
	inline bool operator<(const idfer &other) const
	{
		return cont < other.cont;
	}
};

int n, k, w, q;

ll fac[maxn];
ll rev[maxn];

int len[maxn];
ll anmod[maxn][5];
ll ansum[maxn][5];

ll arr[maxn];
pii queries[maxn];
idfer nqris[maxn];
idfer vals[maxn];
idfer narr[maxn];

ll ncr(ll n, ll r)
{
	return fac[n] * rev[r] % mod * rev[n-r] % mod;
}

void upd(int v)
{
	len[v] = len[2*v] + len[2*v+1];
	int sz = len[2*v];
	for(int i = 0; i < w; i++)
	{
		anmod[v][i] = (anmod[2*v][i] + anmod[2*v+1][(i+sz)%w]) % mod;
	}
	for(int i = 0; i <= k; i++)
	{
		ansum[v][i] = ansum[2*v][i];
	}
	ansum[v][0] = (ansum[2*v][0] + ansum[2*v+1][0]) % mod;
	for(int i = 1; i <= k; i++)
	{
		for(int j = 0; j <= i; j++)
		{
			ansum[v][i] = (ansum[v][i] + ( ansum[2*v+1][j] * bpow(sz, i-j) % mod * ncr(i, j) % mod )) % mod;
		}
	}
}

void debug_ansum(int l, int r, int v)
{
	cerr << "ansum[" << l << "~" << r << "," << v << "]: ";
	for(int i = 0; i <= k; i++)
		cerr << ansum[v][i] << " ";
	cerr << endl;
}

void set_state(int l, int r, int p, bool st, int v)
{
	if(p < l or p >= r)
		return;
	if(r - l == 1)
	{
		len[v] = st;
		for(int i = 0; i < w; i++)
			anmod[v][i] = st * vals[p].cont % w * bpow(i, k) % w;
		for(int i = 0; i <= k; i++)
			ansum[v][i] = st * vals[p].cont % mod * bpow(1, k) % mod;
		return;
	}
	int m = (l+r) / 2;
	set_state(l, m, p, st, 2*v);
	set_state(m, r, p, st, 2*v+1);
	upd(v);
}

ll get()
{
	ll ans = (ansum[1][k] - anmod[1][1] + mod) % mod;
	ans = ans * rev[w] % mod;
	return ans;
}

void debug_vals() 
{
	cerr << "----vals----" << endl;
	for(int i = 0; i < n+q; i++)
		cerr << vals[i].cont << " " << vals[i].validx << " " << vals[i].ogarr << " " << vals[i].ogidx << endl;
	cerr << "--endvals--" << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	fac[0] = 1;
	for(int i = 1; i < maxn; i++)
		fac[i] = fac[i-1] * i % mod;
	rev[maxn-1] = bpow(fac[maxn-1], mod-2);
	for(int i = maxn-2; i >= 0; i--)
		rev[i] = rev[i+1] * (i+1) % mod;
	cin >> n >> k >> w;
	for(int i = 0; i < n; i++)
		cin >> arr[i];
	cin >> q;
	for(int i = 0; i < q; i++)
	{
		cin >> queries[i].first >> queries[i].second;
		queries[i].first--;
	}
	int nlen = n+q;
	for(int i = 0; i < n; i++)
		vals[i] = {arr[i], 0, i, -1};
	for(int i = 0; i < q; i++)
		vals[i+n] = {queries[i].second, 1, i, -1};
	sort(vals, vals+nlen);
	for(int i = 0; i < nlen; i++)
	{
		vals[i].validx = i;
		if(vals[i].ogarr == 0)
		{
			narr[vals[i].ogidx] = vals[i];
			set_state(0, nlen, i, 1, 1);
		}
		else
		{
			nqris[vals[i].ogidx] = vals[i];
		}
	}
	for(int i = 0; i < q; i++)
	{
		int idx = queries[i].first;
		idfer f = narr[idx];
		idfer s = nqris[i];
		set_state(0, nlen, f.validx, 0, 1);
		set_state(0, nlen, s.validx, 1, 1);
		narr[idx] = s;
		cout << get() << endl;
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 28436kb

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: 8ms
memory: 28940kb

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: 4ms
memory: 28792kb

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: 9ms
memory: 29888kb

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: 37ms
memory: 29072kb

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:

33779482
150686050
514427582
834358335
544674287
120375517
817313110
157762813
41121314
561951744
620417559
720606086
205145749
758832436
338140708
820132831
942037425
1588775
71394340
750220815
833603577
164288915
423357535
686058314
389387394
617520724
149836877
42771820
472819174
316818917
756636...

result:

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