QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#208270#7561. Digit DPw4p3rWA 740ms79224kbC++204.5kb2023-10-09 12:54:492023-10-09 12:54:49

Judging History

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

  • [2023-10-09 12:54:49]
  • 评测
  • 测评结果:WA
  • 用时:740ms
  • 内存:79224kb
  • [2023-10-09 12:54:49]
  • 提交

answer

#include<bits/stdc++.h>
#define inf 2e9
#define eps 1e-6
#define FOR(i, a, b) for(int i = a; i <= b; i ++)
#define REP(i, a, b) for(int i = a; i >= b; i --)
#define pb push_back
#define fr first
#define sd second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch = getchar();
	ll s = 0, w = 1;
	while (ch < '0' || ch > '9') {if (ch == '-')w = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {s = s * 10 + ch - '0'; ch = getchar();}
	return s * w;
}
const int mod = 998244353;
#define N 110
#define M 40010
int n, q;
struct node
{
	int s[3], len;
	node() {FOR(i, 0, 2)s[i] = 0; len = 0;}
} t[N * M], s[N];
int ls[N * M], rs[N * M], tag[N * M];
int rt, tot;
int inv2, inv6;
int a[N];
bitset<N>B1[N], B2[N];
int ksm(int a, int b)
{
	int ans = 1;
	while (b) {if (b & 1)ans = 1LL * ans * a % mod; b >>= 1; a = 1LL * a * a % mod;}
	return ans;
}
int C3(int n) {return 1LL * n * (n + mod - 1) % mod * (n + mod - 2) % mod * inv6 % mod;}
int C2(int n) {return 1LL * n * (n + mod - 1) % mod * inv2 % mod;}
node operator +(const node a, const node b)
{
	node c; c.len = (a.len + b.len) % mod;
	c.s[0] = (1LL * a.s[0] + b.s[0]) % mod;
	c.s[1] = (1LL * a.s[1] + b.s[1] + 1LL * a.s[0] * b.s[0]) % mod;
	c.s[2] = (1LL * a.s[2] + b.s[2] + 1LL * a.s[1] * b.s[0] + 1LL * a.s[0] * b.s[1]) % mod;
	return c;
}
node operator +(const node a, const int w)
{
	node c; c.len = a.len;
	c.s[0] = (1LL * a.s[0] + 1LL * a.len * w) % mod;
	c.s[1] = (1LL * a.s[1] + 1LL * a.s[0] * (a.len + mod - 1) % mod * w + 1LL * C2(a.len) * w % mod * w) % mod;
	c.s[2] = (1LL * a.s[2] + 1LL * a.s[1] * (a.len + mod - 2) % mod * w + 1LL * a.s[0] * C2(a.len - 1) * w % mod * w + 1LL * C3(a.len) * w % mod * w % mod * w) % mod;
	return c;
}
char S[N];
bitset<N> Read()
{
	bitset<N>ans;
	scanf("%s", S + 1);
	FOR(i, 1, n)ans[i] = S[i] - '0';
	return ans;
}
void push(int x, int w) {t[x] = t[x] + w; tag[x] = (tag[x] + w) % mod;}
void pushdown(int x, int S, int dep)
{
	if (!ls[x]) {ls[x] = ++ tot; t[ls[x]] = s[dep + 1] + S;}
	if (!rs[x]) {rs[x] = ++ tot; t[rs[x]] = s[dep + 1] + ((a[dep] + S) % mod);}
	if (tag[x]) {push(ls[x], tag[x]); push(rs[x], tag[x]); tag[x] = 0;}
}
void pushup(int x) {t[x] = t[ls[x]] + t[rs[x]];}
void print(bitset<N>L, bitset<N> R, int dep)
{
	cout << "MODIFY:" << dep << endl;
	FOR(i, 1, n)cout << L[i]; cout << endl;
	FOR(i, 1, n)cout << R[i]; cout << endl;
}
void add(int &x, const bitset<N>ql, const bitset<N>qr, int dep, int S, int w)
{
	if (!x) {x = ++tot; t[tot] = s[dep] + S;}
	if (((ql & B1[dep]) == 0) && ((qr & B1[dep]) == B1[dep])) {/*print(ql, qr, dep); cout << "???:" << t[x].len << " " << t[x].s[0] << ' ' << t[x].s[1] << ' ' << t[x].s[2] << endl;;*/ push(x, w); return ;}
	pushdown(x, S, dep);
	if (qr[dep] == 0)add(ls[x], ql, qr, dep + 1, S, w);
	else if (ql[dep] == 1)add(rs[x], ql, qr, dep + 1, (S + a[dep]) % mod, w);
	else
	{
		add(ls[x], ql, B1[dep + 1], dep + 1, S, w);
		add(rs[x], 0, qr, dep + 1, (S + a[dep]) % mod, w);
	}
	// print(ql, qr, dep);
	pushup(x);
	// cout << "???:" << t[x].len << " " << t[x].s[0] << ' ' << t[x].s[1] << ' ' << t[x].s[2] << endl;;
}
int qry(int &x, const bitset<N>ql, const bitset<N>qr, int dep, int S)
{
	if (!x) {x = ++tot; t[tot] = s[dep] + S;}
	if (((ql & B1[dep]) == 0) && ((qr & B1[dep]) == B1[dep])) return t[x].s[2];
	pushdown(x, S, dep);
	if (qr[dep] == 0)return qry(ls[x], ql, qr, dep + 1, S);
	else if (ql[dep] == 1)return qry(rs[x], ql, qr, dep + 1, (S + a[dep]) % mod);
	else
	{
		int s = 0;
		s = (s + qry(ls[x], ql, B1[dep + 1], dep + 1, S)) % mod;
		s = (s + qry(rs[x], 0, qr, dep + 1, (S + a[dep]) % mod)) % mod;
		return s;

	}
}
int main()
{
	// freopen("C.in", "r", stdin);
	// freopen("C.out", "w", stdout);
	inv2 = ksm(2, mod - 2);
	inv6 = ksm(6, mod - 2);
	n = read(), q = read();
	FOR(i, 1, n)
	{
		B2[i] = B2[i - 1];
		B2[i][i] = 1;
	}
	REP(i, n, 1)
	{
		B1[i] = B1[i + 1];
		B1[i][i] = 1;
	}
	FOR(i, 1, n)a[i] = read() % mod;
	reverse(a + 1, a + n + 1);
	s[n + 1].len = 1;
	REP(i, n, 1)
	{
		s[i] = s[i + 1] + (s[i + 1] + a[i]);
	}
	// FOR(i, 1, n)
	// cout << s[i].len << ' ' << s[i].s[0] << ' ' << s[i].s[1] << ' ' << s[i].s[2] << endl;
	while (q --)
	{
		int op = read(); bitset<N>L = Read(), R = Read();
		if (op == 1)
		{
			int w = read();
			add(rt, L, R, 1, 0, w);
		}
		else cout << qry(rt, L, R, 1, 0) << '\n';
	}
	return 0;
}
/*
3 3
1 2 4
2 000 111
1 010 101 1
2 000 111
*/
/*
2 2
1 1
2 00 10
2 00 11
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 73912kb

input:

3 3
1 2 4
2 000 111
1 010 101 1
2 000 111

output:

1960
3040

result:

ok 2 number(s): "1960 3040"

Test #2:

score: 0
Accepted
time: 4ms
memory: 73548kb

input:

2 2
1 1
2 00 10
2 00 11

output:

0
2

result:

ok 2 number(s): "0 2"

Test #3:

score: -100
Wrong Answer
time: 740ms
memory: 79224kb

input:

99 49952
470888 74578 802746 396295 386884 721198 628655 722503 207868 647942 87506 792718 761498 917727 843338 908043 952768 268783 375312 414369 319712 96230 277106 168102 263554 936674 246545 667941 198849 268921 191459 436316 134606 802932 515506 837311 465964 394766 17626 650419 984050 790137 4...

output:

901584734
963957407
400507314
664981671
441999993
177001799
952946324
530640678
398014521
276143660
34031664
-88353756
333535914
154474382
200809186
585109836
563608984
939555965
751654926
611877595
134866719
804173612
472857580
616100436
402867867
43493692
788765239
444679093
931265348
556636837
73...

result:

wrong answer 1st numbers differ - expected: '413449847', found: '901584734'