QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#402494#8601. Герої та Монстриoscaryang0 63ms395556kbC++202.4kb2024-04-30 17:27:572024-04-30 17:27:58

Judging History

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

  • [2024-04-30 17:27:58]
  • 评测
  • 测评结果:0
  • 用时:63ms
  • 内存:395556kb
  • [2024-04-30 17:27:57]
  • 提交

answer

#include<bits/stdc++.h>

#define vc vector
#define pb emplace_back
#define pii pair<int, int>
#define mkp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define lep(i, a, b) for(int i = (a); i >= (b); --i)

using namespace std;

mt19937 gen(time(0));

inline int read() {
	int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch == '-'), ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return w ? -x : x; 
}

const int N = 5005, MOD = 998244353;

// CALC
inline void inc (int &x, int y) { x += y - MOD; x += (x >> 31) & MOD; }
inline int qpow (int a, int b) { int res = 1; for(; b; b >>= 1, a = 1ll * a * a % MOD) if(b & 1) res = 1ll * res * a % MOD; return res; }
inline int qinv (int a) { return qpow(a, MOD - 2); }

struct mint {
	int x; 
	mint (int ix = 0) { x = ix % MOD; if(x < 0) x += MOD; }
	mint operator += (mint a) { inc (x, a.x); return a; }
	mint operator -= (mint a) { inc (x, MOD - a.x); return a; }
	mint operator *= (mint a) { x = 1ll * x * a.x % MOD; return a; }
	mint friend operator + (mint a, mint b) { a += b; return a; }
	mint friend operator - (mint a, mint b) { a -= b; return a; }
	mint friend operator * (mint a, mint b) { a *= b; return a; }
} f[N << 1][N], g[N << 1][N], ans[N];  

int n, m, a[N], b[N];
pii A[N << 1];

signed main() {
	n = read (); A[0] = mkp (1, 0);
	rep (i, 1, n) A[a[i] = read ()] = mkp (0, i);
	rep (i, 1, n) A[b[i] = read ()] = mkp (1, i);
	
	{
		int ca = 0, cb = 0;
		f[0][0] = 1;
		rep (i, 1, 2 * n) {
			auto [u, v] = A[i];
			if (u == 0) {
				++ ca;
				rep (j, 0, min (ca, cb)) f[i][j] = f[i - 1][j] + f[i - 1][j - 1];
			}
			else {
				++ cb;
				rep (j, 0, min (ca, cb)) f[i][j] = f[i - 1][j];
			}
		}
	}
	
	{
		int ca = 0, cb = 0;
		g[2 * n + 1][0] = 1;
		lep (i, 2 * n, 1) {
			auto [u, v] = A[i];
			if (u == 0) {
				++ ca; 
				rep (j, 0, min (ca, cb)) g[i][j] = g[i + 1][j] + g[i + 1][j - 1];
			}
			else {
				++ cb;
				rep (j, 0, min (ca, cb)) g[i][j] = g[i + 1][j];
			}
		}
	}
	
	int pr = 0, sf = n;
	rep (i, 0, 2 * n) {
		auto [u, v] = A[i];
		if (!u) { ++ pr, -- sf; continue; }
		ans[v + 1] += ans[v];
		rep (j, 0, pr) ans[v + 1] += f[i][j] * g[i][sf - (i - pr - j)];
	}
	
	m = read ();
	for (int i = 1, l, r; i <= m; i ++)
		l = read (), r = read (), printf ("%d\n", (ans[r + 1] - ans[l]).x);
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 60ms
memory: 395432kb

input:

5000
1903 4400 1211 1700 2191 4378 4216 4601 2907 2029 3009 1858 4926 2981 2848 1345 689 4704 3137 51 1755 787 4679 1555 496 4259 3989 1122 3983 3966 3493 2869 4203 823 410 3144 738 41 3977 1767 2663 4779 3252 1930 4989 3003 1269 1604 3888 1737 3776 351 1035 4600 3740 1534 4846 2440 3725 838 76 2786...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 827th numbers differ - expected: '1', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 63ms
memory: 395424kb

input:

5000
2034 4850 3399 4589 4777 643 1832 1410 3705 2859 3002 1824 2063 2342 2885 1715 2531 2809 1389 1050 3167 374 242 368 4346 1850 3418 4129 4626 2762 1365 4440 3165 857 1042 61 713 2313 4467 2864 29 4725 4959 571 4753 378 4674 1960 1654 21 1704 4401 2068 3375 2092 2086 3004 4179 2865 2619 2873 4755...

output:

0

result:

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

Subtask #3:

score: 0
Wrong Answer

Test #41:

score: 0
Wrong Answer
time: 56ms
memory: 395328kb

input:

5000
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173 17...

output:

994748608
429378898
422021660
266302003
522435378
48707405
2144726
678815219
140533013
613284916
648265601
217683840
166565886
499391846
936868275
995936044
314638951
774740859
376651350
852169707
556944839
544215045
142967797
833525452
203481130
57698843
653411997
234992791
33891015
301758386
27955...

result:

wrong answer 2398th numbers differ - expected: '651189440', found: '651189439'

Subtask #4:

score: 0
Wrong Answer

Test #71:

score: 0
Wrong Answer
time: 27ms
memory: 395328kb

input:

300
127 142 125 327 217 438 162 129 16 370 452 170 418 357 397 446 398 597 5 296 558 159 140 566 433 132 302 565 472 513 477 198 350 467 177 160 272 155 251 440 84 176 387 112 237 578 258 278 26 74 332 6 136 400 367 273 535 146 252 141 11 484 285 465 474 512 373 462 480 207 505 580 114 22 340 42 288...

output:

883283732

result:

wrong answer 1st numbers differ - expected: '268091962', found: '883283732'

Subtask #5:

score: 0
Wrong Answer

Test #101:

score: 0
Wrong Answer
time: 60ms
memory: 395556kb

input:

5000
214 8143 377 4551 6212 1807 4966 4535 3579 997 7830 3921 7330 6511 8039 1554 3258 9014 4821 7807 1039 7535 4022 2642 2781 8442 3246 141 9033 2806 9569 8010 565 2546 6114 7896 4315 3054 384 1100 9263 9236 8117 8983 8184 2987 5491 8267 1271 5488 3990 494 2917 6363 3528 8154 3334 4216 8742 2805 53...

output:

707086935

result:

wrong answer 1st numbers differ - expected: '670627274', found: '707086935'

Subtask #6:

score: 0
Wrong Answer

Test #131:

score: 0
Wrong Answer
time: 52ms
memory: 395368kb

input:

5000
3846 2428 4235 4639 1041 2385 198 6154 6899 8917 6284 9752 8913 2027 9242 6979 498 2562 5915 3968 9943 2767 3776 3415 3532 1826 8061 9507 6540 1850 2235 7245 5751 5780 3048 23 361 2777 262 8551 4969 1367 8671 7424 504 5822 3056 6816 9246 6810 1643 8378 9672 7472 4092 8226 5973 157 9275 4757 619...

output:

80671855

result:

wrong answer 1st numbers differ - expected: '293162006', found: '80671855'

Subtask #7:

score: 0
Skipped

Dependency #4:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%