QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#640669#9438. Two BoxHuTaoWA 12ms37256kbC++144.6kb2024-10-14 15:08:222024-10-14 15:08:22

Judging History

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

  • [2024-10-14 15:08:22]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:37256kb
  • [2024-10-14 15:08:22]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 30004, M = 17, K = 32, P = 998244353, INV2 = (P + 1) / 2;

int n, m, q;
int a[N];
struct Node{
	int a, b;
	int v, s;
	LL f[K];
}t[M][N * 4];
LL p[N][K + 2];

#define ls (u << 1)
#define rs (u << 1 | 1)
inline void PushUp0(const int &k, const int &u)
{
	t[k][u].v = t[k][ls].v | t[k][rs].v;
}
inline void Build(const int &k, const int &u, const int &a, const int &b)
{
	t[k][u].a = a, t[k][u].b = b, t[k][u].v = b - a + 1;
	for(int i = 0; i < m * 2; i ++ ) t[k][u].f[i] = 1;
	if(a != b)
	{
		int mid = (a + b) >> 1;
		Build(k, ls, a, mid);
		Build(k, rs, mid + 1, b);
	}
}
inline void Change(const int &k, const int &u, const int &x)
{
	if(t[k][u].a == t[k][u].b)
	{
		t[k][u].v ^= 1;
		return ;
	}
	if(t[k][ls].b >= x) Change(k, ls, x);
	else Change(k, rs, x);
	PushUp0(k, u);
}
inline int Prev(const int &k, const int &u, const int &x)
{
	if(t[k][u].a == t[k][u].b) return t[k][u].a;
	int res = 0;
	if(t[k][rs].v && t[k][rs].a <= x) res = Prev(k, rs, x);
	if(res) return res;
	if(t[k][ls].v) res = Prev(k, ls, x);
	return res;
}
inline int Next(const int &k, const int &u, const int &x)
{
	if(t[k][u].a == t[k][u].b) return t[k][u].a;
	int res = n + 1;
	if(t[k][ls].v && t[k][ls].b >= x) res = Next(k, ls, x);
	if(res != n + 1) return res;
	if(t[k][rs].v) res = Next(k, rs, x);
	return res;
}

inline void PushUp1(const int &k, const int &u)
{
	t[k][u].s = t[k][ls].s + t[k][rs].s;
	for(int i = 0; i < m * 2; i ++ )
		t[k][u].f[i] = t[k][ls].f[i] * t[k][rs].f[i] % P;
}
inline void Modify(const int &k, const int &u, const int &x, const LL f[], const int &s)
{
	if(t[k][u].a == t[k][u].b)
	{
		t[k][u].s = s;
		memcpy(t[k][u].f, f, sizeof t[k][u].f);
		return ;
	}
	if(t[k][ls].b >= x) Modify(k, ls, x, f, s);
	else Modify(k, rs, x, f, s);
	PushUp1(k, u);
}
inline void Query(const int &k, const int &u, const int &x, const int &y, LL f[], int &s)
{
	if(x <= t[k][u].a && t[k][u].b <= y)
	{
		s += t[k][u].s;
		for(int i = 0; i < m * 2; i ++ )
			f[i] = f[i] * t[k][u].f[i] % P;
		return ;
	}
	if(t[k][ls].b >= x) Query(k, ls, x, y, f, s);
	if(t[k][rs].a <= y) Query(k, rs, x, y, f, s);
}
LL tmp[K], tmp0[K];
inline void Delete(const int &k, const int &x)
{
//	printf("#%d %d\n", k, x);
	for(int i = 0; i < m * 2; i ++ ) tmp[i] = 1;
	Modify(k, 1, x, tmp, 0);
}
inline void Calc(const int &k, const int &x)
{
	int l = Prev(k, 1, x) + 1, tr = Next(k, 1, x) - 1, r = min(n, tr + 1);
//	printf("#%d %d %d %d\n", x, k, l, r);
	if(l > r) return ;
	Delete(k, l), Delete(k, x + 1);
	if(k != m)
	{
		for(int i = 0; i < m * 2; i ++ ) tmp[i] = 1;
		int s = 0;
		Query(k + 1, 1, l, r, tmp, s);
		s = r - l + 1 - s;
		for(int i = 0; i < m * 2; i ++ ) tmp[i] = tmp[i] * p[s][i + 1] % P;
		if(tr == n)
		{
			for(int i = 0; i < m * 2 - 1; i ++ ) tmp0[i] = tmp[i + 1];
		}
		else
		{
			for(int i = 1; i < m * 2 - 1; i ++ ) tmp0[i] = (tmp[i - 1] + tmp[i + 1]) * INV2 % P;
		}
//		printf("*%d\n", s);
//		for(int i = 0; i < m * 2; i ++ )
//		{
//			if(i == m) printf("*");
//			printf("%lld ", tmp0[i]);	
//		}
//		puts("");
		Modify(k, 1, l, tmp0, r - l + 1);
	}
	else
	{
		if(tr == n)
		{
			for(int i = 0; i < m * 2; i ++ ) tmp[i] = p[r - l + 1][i + 2];
		}
		else
		{
			for(int i = 0; i < m * 2; i ++ ) tmp[i] = (p[r - l + 1][i] + p[r - l + 1][i + 2]) * INV2 % P;
		}
//		for(int i = 0; i < m * 2; i ++ )
//		{
//			if(i == m) printf("*");
//			printf("%lld ", tmp[i]);	
//		}
//		puts("");
		Modify(k, 1, l, tmp, r - l + 1);
	}
}
inline LL Modify(int x, int d)
{
	if(a[x] == d) return t[2][1].f[m];
	for(int i = 2; i <= a[x]; i ++ ) Delete(i, Prev(i, 1, x) + 1);
	if(a[x] > d)
	{
		for(int i = a[x]; i > d; i -- )
		{
			Change(i, 1, x);
			if(x > 1) Calc(i, x - 1);
			if(x < n) Calc(i, x + 1);
		}
	}
	else
	{
		for(int i = d; i > a[x]; i -- )
		{
			Change(i, 1, x);
			Calc(i, x);
		}
	}
	for(int i = min(d, a[x]); i >= 2; i -- ) Calc(i, x);
	a[x] = d;
	return t[2][1].f[m];
}

int main()
{
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
	
	for(int i = 0; i <= m * 2 + 1; i ++ ) p[0][i] = 1;
	for(int i = 1; i <= n;i ++ )
		for(int j = 0; j <= m * 2 + 1; j ++ )
			p[i][j] = p[i - 1][j] * (j - m + P) % P;
	for(int i = 1; i <= m; i ++ ) Build(i, 1, 1, n);
	for(int i = 1; i <= n; i ++ )
	{
		int t = a[i];
		a[i] = 1;
		Modify(i, t);
	}
	for(int i = 1; i <= q; i ++ )
	{
		int x, y;
		scanf("%d%d", &x, &y);
		printf("%lld\n", Modify(x, y));
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9940kb

input:

3 3 2
1 3 1
3 2
1 3

output:

5
14

result:

ok 2 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 20184kb

input:

6 8 1
3 8 7 7 1 6
1 4

output:

2100

result:

ok "2100"

Test #3:

score: 0
Accepted
time: 0ms
memory: 24324kb

input:

12 10 8
1 3 2 6 3 6 7 7 5 5 4 7
12 4
7 10
4 2
9 8
9 9
8 3
4 9
10 2

output:

2741280
3007680
1503840
1916160
1972800
728640
1821600
621440

result:

ok 8 tokens

Test #4:

score: 0
Accepted
time: 7ms
memory: 20768kb

input:

1939 5 1
5 1 1 2 1 5 4 5 3 1 2 1 3 3 1 2 3 5 5 3 2 2 1 3 1 5 1 4 2 5 4 1 5 4 3 4 5 3 3 3 3 2 1 2 3 5 1 4 2 1 4 1 3 5 2 2 1 4 4 5 3 2 3 2 1 1 5 5 5 5 3 4 3 1 3 1 1 1 3 5 3 5 1 5 4 3 2 1 2 2 2 3 5 2 4 2 3 1 2 5 5 1 2 5 2 5 3 3 3 4 5 1 5 4 5 3 3 5 4 5 3 5 3 2 2 5 3 2 4 3 3 4 2 2 1 3 1 3 5 2 3 4 2 3 2 4...

output:

894246250

result:

ok "894246250"

Test #5:

score: 0
Accepted
time: 0ms
memory: 24408kb

input:

245 9 1
2 2 3 6 7 5 7 4 7 9 7 6 3 1 6 8 2 1 1 5 3 1 1 3 1 6 8 4 8 4 8 1 8 6 6 9 3 4 7 1 5 2 3 9 5 7 5 7 7 5 5 5 5 1 5 4 7 1 2 6 8 9 5 4 1 8 6 3 9 9 1 3 6 5 5 5 1 6 5 1 2 5 5 4 1 1 8 3 8 2 9 7 9 5 7 8 8 5 9 1 1 4 4 9 9 6 3 9 8 9 2 1 2 6 9 2 1 3 7 3 2 5 9 3 7 2 2 3 4 7 5 1 8 5 8 6 7 9 7 4 8 7 2 2 7 5 ...

output:

99945033

result:

ok "99945033"

Test #6:

score: 0
Accepted
time: 9ms
memory: 35040kb

input:

1919 9 1
7 1 7 6 6 9 8 5 1 8 9 9 7 3 4 2 8 9 4 8 7 4 8 8 8 4 2 9 5 9 3 7 2 3 2 8 7 9 1 1 3 7 7 2 5 9 2 1 3 6 7 6 4 4 1 9 3 7 3 2 5 5 1 4 7 8 6 2 1 4 7 1 4 7 4 7 6 3 8 4 3 7 3 1 7 5 2 2 2 4 9 1 5 5 7 7 3 1 5 4 7 2 9 5 4 9 3 2 6 8 2 3 8 3 6 5 5 5 9 7 2 8 2 9 5 1 8 6 3 1 2 9 1 9 1 3 9 6 7 2 3 2 2 7 9 7...

output:

292474819

result:

ok "292474819"

Test #7:

score: 0
Accepted
time: 3ms
memory: 20888kb

input:

1985 5 1
1 5 5 1 4 4 3 2 1 4 4 1 1 2 5 5 5 3 3 1 2 4 3 3 5 5 2 4 1 1 5 4 3 1 2 5 5 4 1 5 2 5 2 4 1 4 5 1 3 4 4 2 2 4 5 2 1 5 5 3 2 5 5 2 4 4 5 2 5 1 1 5 5 1 1 3 4 2 4 5 2 1 2 1 1 2 3 5 1 5 2 4 1 5 3 2 2 3 1 3 4 5 1 4 4 2 4 3 5 5 1 4 3 4 5 5 2 5 2 2 2 2 2 3 5 1 4 4 3 3 4 5 5 4 3 5 1 4 5 5 2 3 2 2 3 3...

output:

810807913

result:

ok "810807913"

Test #8:

score: 0
Accepted
time: 0ms
memory: 14236kb

input:

357 5 1
1 3 2 5 4 4 3 4 3 1 1 1 4 5 5 2 1 3 4 1 3 1 2 3 4 1 5 3 1 3 5 1 4 4 2 4 5 1 3 4 2 5 2 3 2 5 3 2 2 1 4 3 1 1 2 3 2 3 2 1 4 4 5 5 1 4 2 1 2 2 2 4 1 3 5 1 1 2 4 4 5 4 1 2 4 1 2 3 2 4 3 4 3 4 1 4 1 1 4 5 4 4 4 3 2 5 4 5 4 2 4 1 2 5 5 3 5 5 2 4 2 1 2 1 4 1 2 1 3 1 5 2 2 1 5 2 2 4 5 1 3 4 5 3 3 3 ...

output:

836628563

result:

ok "836628563"

Test #9:

score: 0
Accepted
time: 3ms
memory: 28644kb

input:

858 10 1
1 9 2 9 6 9 6 10 9 4 1 9 7 7 9 2 5 6 9 3 4 7 4 2 5 10 8 10 4 8 8 1 2 9 10 9 5 9 1 2 1 8 10 2 8 1 10 6 9 5 2 4 9 4 1 5 6 10 7 5 1 7 6 7 9 8 4 4 1 8 1 4 4 10 8 10 1 1 1 2 6 3 6 9 8 10 4 5 8 3 6 7 2 9 9 7 9 10 5 7 4 9 4 7 3 1 10 2 6 4 1 5 8 7 1 6 1 2 8 8 1 3 6 8 5 3 10 9 8 4 8 5 2 2 2 10 8 1 8...

output:

699591879

result:

ok "699591879"

Test #10:

score: 0
Accepted
time: 2ms
memory: 20460kb

input:

884 7 1
7 2 6 7 1 7 2 5 5 1 7 5 4 5 2 5 4 2 2 4 3 2 7 1 6 3 3 2 1 1 2 1 7 7 4 3 5 1 1 6 6 7 5 1 6 6 4 3 5 2 3 1 6 3 7 2 7 4 6 6 6 3 7 6 1 3 2 1 1 5 4 3 1 4 4 4 7 2 5 7 5 7 5 3 6 5 5 1 4 5 6 6 6 3 6 7 3 2 3 1 5 5 6 7 6 5 3 2 7 3 1 2 5 5 1 2 7 5 3 1 3 6 4 7 2 4 4 5 6 7 4 7 4 2 4 1 2 1 2 6 7 1 7 4 1 1 ...

output:

298342150

result:

ok "298342150"

Test #11:

score: 0
Accepted
time: 10ms
memory: 37168kb

input:

2000 10 1
7 2 5 8 9 1 9 9 5 4 3 3 9 7 3 2 1 9 9 6 4 9 10 10 1 1 2 4 6 7 9 9 5 5 8 1 3 9 5 2 5 7 10 8 5 10 1 9 8 10 2 1 9 4 1 10 8 3 10 4 4 7 5 6 6 1 4 4 4 6 5 10 5 7 7 9 2 3 9 4 8 8 9 9 4 6 5 9 5 4 3 10 3 5 7 5 9 8 1 9 2 9 4 3 3 4 6 3 1 5 2 10 2 2 3 4 5 2 4 6 2 9 5 10 5 2 9 4 9 8 8 7 5 7 3 10 2 6 6 ...

output:

593281642

result:

ok "593281642"

Test #12:

score: 0
Accepted
time: 12ms
memory: 35100kb

input:

2000 10 1
4 3 9 2 9 3 9 2 7 1 4 10 1 10 8 10 1 6 9 5 7 5 10 10 1 10 5 7 1 5 5 8 10 10 4 10 6 6 1 9 8 5 2 3 5 3 1 1 3 3 6 2 6 9 8 4 10 8 7 8 9 10 5 3 6 3 2 4 10 1 10 8 7 10 7 1 4 3 2 8 8 7 7 9 1 7 5 3 5 7 6 6 9 8 8 8 9 7 10 8 3 5 5 1 3 10 9 1 9 2 10 9 3 1 6 1 7 10 9 9 9 3 6 9 2 10 6 1 5 2 2 5 6 6 9 1...

output:

635535966

result:

ok "635535966"

Test #13:

score: 0
Accepted
time: 7ms
memory: 37144kb

input:

2000 10 1
7 6 2 4 9 3 2 10 6 2 3 2 8 7 4 1 6 7 1 10 4 9 7 2 5 2 5 10 6 6 5 3 7 4 10 6 4 8 7 9 6 10 10 3 10 4 3 6 6 6 8 5 6 4 3 9 2 9 8 5 6 5 5 4 9 7 6 1 7 1 8 10 3 1 10 3 4 4 9 10 10 7 8 4 4 6 9 3 6 3 4 4 3 4 7 1 6 2 6 4 9 10 4 2 7 7 10 4 4 1 10 2 8 6 8 2 8 1 4 10 3 6 1 1 7 9 3 9 6 2 3 9 8 3 7 9 3 8...

output:

336713065

result:

ok "336713065"

Test #14:

score: 0
Accepted
time: 12ms
memory: 35108kb

input:

2000 10 1
10 10 2 4 8 7 8 9 8 7 5 10 8 2 5 5 1 3 10 5 4 3 6 3 9 9 10 9 9 9 6 10 6 2 9 3 7 4 7 10 2 4 7 3 9 3 7 10 5 9 10 7 8 1 7 7 9 10 6 4 10 4 3 6 10 5 4 7 5 6 8 8 1 6 5 7 7 5 4 2 5 8 5 9 9 9 7 10 2 9 7 6 1 8 9 2 4 1 9 8 7 9 4 2 3 2 3 2 7 5 4 8 8 2 4 8 6 4 1 3 3 9 7 10 7 7 3 8 1 1 4 2 3 4 10 8 8 8...

output:

85227947

result:

ok "85227947"

Test #15:

score: 0
Accepted
time: 11ms
memory: 37156kb

input:

2000 10 1
1 7 2 8 1 9 7 7 6 2 4 2 1 5 2 6 1 10 2 8 5 1 6 8 5 9 10 5 8 2 1 2 8 6 2 3 7 9 10 10 10 9 9 3 6 1 7 8 4 8 9 7 9 5 1 3 8 1 3 4 1 6 6 5 9 6 7 8 10 10 4 9 5 6 10 7 2 3 4 7 3 8 6 3 5 2 2 9 9 5 8 3 6 8 2 1 4 3 4 2 3 9 6 4 5 6 8 1 2 1 3 10 4 5 7 2 9 4 10 6 1 6 1 2 10 2 3 9 5 9 1 6 10 2 8 6 10 6 1...

output:

913697441

result:

ok "913697441"

Test #16:

score: 0
Accepted
time: 11ms
memory: 35164kb

input:

2000 10 1
7 9 2 6 9 1 10 1 8 3 4 5 1 10 6 10 4 10 3 1 10 2 10 8 3 5 2 2 4 9 5 7 2 4 8 5 7 5 1 10 8 10 5 8 10 4 2 9 8 9 6 3 7 10 1 7 6 9 4 10 8 5 1 3 5 7 3 6 3 2 8 5 6 2 8 2 7 6 1 6 7 4 3 5 8 3 8 9 5 6 2 8 2 4 5 2 4 1 3 9 7 1 5 9 9 2 3 2 1 8 6 1 3 6 7 3 5 5 8 3 9 5 9 1 7 2 3 5 1 7 8 10 3 4 10 8 3 6 8...

output:

298067446

result:

ok "298067446"

Test #17:

score: 0
Accepted
time: 8ms
memory: 37256kb

input:

2000 10 1
3 6 1 8 2 3 8 7 9 8 8 5 3 4 4 2 9 1 2 4 7 3 3 3 2 3 9 9 4 4 1 1 1 2 2 4 3 7 8 2 2 1 9 2 7 10 9 5 10 8 1 8 6 2 4 9 2 7 8 2 2 1 1 8 10 8 7 7 1 5 2 4 9 3 2 1 7 1 1 6 1 7 1 7 6 9 6 1 2 3 6 10 3 10 3 2 6 7 10 6 2 6 2 6 7 2 2 7 2 1 6 5 10 5 2 2 10 4 1 9 8 8 7 6 1 9 2 4 1 4 5 7 5 3 10 4 9 5 2 8 8...

output:

307824286

result:

ok "307824286"

Test #18:

score: -100
Wrong Answer
time: 0ms
memory: 8512kb

input:

2000 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

0

result:

wrong answer 1st words differ - expected: '1', found: '0'