QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#487204#8601. Герої та Монстриgreen_gold_dog3 2ms4212kbC++202.4kb2024-07-22 18:06:592024-07-22 18:06:59

Judging History

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

  • [2024-07-22 18:06:59]
  • 评测
  • 测评结果:3
  • 用时:2ms
  • 内存:4212kb
  • [2024-07-22 18:06:59]
  • 提交

answer

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;

constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 998'244'353;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;

random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());

template<typename T>
bool assign_max(T& a, T b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
bool assign_min(T& a, T b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
T square(T a) {
	return a * a;
}

template<>
struct std::hash<pair<ll, ll>> {
	ll operator() (pair<ll, ll> p) const {
		return ((__int128)p.first * MOD + p.second) % INF64;
	}
};

void solve() {
	ll n;
	cin >> n;
	vector<ll> a(n), b(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (ll i = 0; i < n; i++) {
		cin >> b[i];
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	ll q;
	cin >> q;
	vector<pair<ll, ll>> qs(q);
	vector<ll> add(n + 1, 0), dec(n + 1, 0);
	for (ll i = 0; i < q; i++) {
		cin >> qs[i].first >> qs[i].second;
		add[qs[i].first]++;
		dec[qs[i].second]++;
	}
	vector<ll> all(n + 1, 0);
	ll sum = 0;
	for (ll i = 0; i <= n; i++) {
		sum += add[i];
		if (sum == 0) {
			continue;
		}
		continue;
		vector<ll> dp(i + 1, 0);
		dp[0] = 1;
		for (ll j = 0; j < n; j++) {
			vector<ll> ndp(i + 1, 0);
			for (ll k = 0; k <= min(i, j); k++) {
				ll ost = j - k;
				if (i + ost < n && a[j] <= b[i + ost]) {
					ndp[k] += dp[k];
					if (ndp[k] >= MOD) {
						ndp[k] -= MOD;
					}
				}
				if (k < i && a[j] > b[k]) {
					ndp[k + 1] += dp[k];
					if (ndp[k + 1] >= MOD) {
						ndp[k + 1] %= MOD;
					}
				}
			}
			swap(dp, ndp);
		}
		all[i] = dp.back();
		sum -= dec[i];
	}
	all[0] = 1;
	vector<ll> pref(1, 0);
	for (ll i = 0; i <= n; i++) {
		pref.push_back(pref.back() + all[i]);
	}
	for (ll i = 0; i < q; i++) {
		cout << (pref[qs[i].second + 1] - pref[qs[i].first]) % MOD << '\n';
	}
}

int main() {
	if (IS_FILE) {
		freopen("", "r", stdin);
		freopen("", "w", stdout);
	}
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	cout.tie(0);
	ll t = 1;
	if (IS_TEST_CASES) {
		cin >> t;
	}
	for (ll i = 0; i < t; i++) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 2ms
memory: 3880kb

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:

ok 5001 numbers

Test #2:

score: 3
Accepted
time: 2ms
memory: 4008kb

input:

5000
47 830 2838 2650 4996 1824 865 2629 29 1135 2703 3815 4646 1142 565 1101 3002 1996 1319 426 2333 4683 1274 420 3343 1648 2806 4480 4895 1438 4760 3064 3523 4767 1879 3250 4142 604 4064 2723 3145 2663 1463 2982 4195 4422 2005 3662 1692 276 1209 4271 1709 1878 1522 2130 2216 2875 4099 2682 4706 1...

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:

ok 5001 numbers

Test #3:

score: 3
Accepted
time: 2ms
memory: 3924kb

input:

5000
4013 1760 2726 4336 4597 3326 2242 297 977 4208 4047 1444 3596 675 145 4151 4797 2635 1464 1639 2472 4078 1814 465 11 300 3636 2529 4735 32 4937 3342 314 3957 143 1465 1604 3367 162 1919 4882 3462 3322 1966 4086 1397 3651 4367 2407 787 4395 3731 2724 2040 842 4248 1728 4463 1023 3922 3099 3887 ...

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:

ok 5001 numbers

Test #4:

score: 3
Accepted
time: 2ms
memory: 3924kb

input:

5000
4256 1360 45 1462 4736 2351 1807 2308 3520 1265 357 2847 446 2317 1638 2817 3472 4036 1722 2165 3364 2852 2187 843 516 456 1553 3609 3264 4263 3846 908 1659 4752 920 635 3202 2080 2291 2185 4172 477 4869 462 4376 4255 4666 3686 4094 4619 4531 1406 3519 2850 359 2893 63 2432 522 2117 1168 2282 8...

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:

ok 5001 numbers

Test #5:

score: 3
Accepted
time: 2ms
memory: 4176kb

input:

5000
4108 1176 3492 1954 2420 2760 3353 3589 3890 666 2108 4731 1318 3414 2786 829 1930 3567 335 594 2483 3142 635 2328 1604 3542 2513 541 4406 2942 2542 1133 2304 641 3856 334 2083 2329 1934 4716 2041 3674 188 1811 3439 3898 4382 1002 362 3724 554 3226 1836 137 368 410 632 1129 4508 2765 854 379 37...

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:

ok 5001 numbers

Test #6:

score: 3
Accepted
time: 2ms
memory: 3920kb

input:

5000
1353 3491 635 4602 1156 699 1405 4303 4954 1251 1407 1982 2732 4462 761 3370 3383 3963 2174 1933 4839 3884 1633 453 4268 1790 3408 487 4593 4663 1884 2609 2501 4679 4756 3543 2644 68 3556 1390 2240 4121 3363 1144 392 2657 853 3481 4274 3187 3878 4350 122 494 4966 1033 1070 3095 2372 4278 423 24...

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:

ok 5001 numbers

Test #7:

score: 3
Accepted
time: 2ms
memory: 4212kb

input:

5000
2178 2292 4600 363 3742 2058 2043 637 4433 4144 2768 2191 4705 3614 851 3534 3206 4898 1937 852 1891 2908 1221 3693 1389 2648 4678 2356 2850 4984 3793 2876 2803 3572 4489 595 1236 604 1344 193 2800 3423 3654 689 4734 880 734 1045 2615 4812 582 2389 3661 4349 2294 4886 2589 2459 1644 865 2365 41...

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:

ok 5001 numbers

Test #8:

score: 3
Accepted
time: 2ms
memory: 3908kb

input:

5000
1081 3555 399 4405 890 144 3498 1382 4744 4341 4417 3580 4546 2961 2818 1751 68 2123 2051 39 984 3756 977 1225 4713 4740 765 309 1199 2559 4298 1838 1671 2207 1625 1764 4636 2920 1083 1182 3535 4715 2437 1997 3322 2889 1411 1685 1276 1357 4931 801 2203 3933 4786 2688 3747 4194 1688 1074 1156 11...

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:

ok 5001 numbers

Test #9:

score: 3
Accepted
time: 2ms
memory: 4012kb

input:

5000
3491 1219 3234 587 2840 4720 1321 4512 2699 3931 4694 3202 427 2785 1529 3736 4225 730 4842 3467 1346 1477 2884 3270 3140 373 1685 3661 4047 103 725 4043 2578 3672 1452 4941 1955 3068 3871 3122 3533 303 4008 2470 1910 3832 1513 4893 1914 2746 2161 106 4221 4470 3913 4844 3476 4081 1213 1214 219...

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:

ok 5001 numbers

Test #10:

score: 3
Accepted
time: 2ms
memory: 3940kb

input:

5000
1326 2770 2439 2702 3928 4438 513 1590 4449 4294 4820 381 2898 3027 3665 3731 4593 2308 3597 1153 2009 2982 4079 3656 4214 3071 3526 864 328 3047 331 283 3671 900 2626 3850 2043 2274 690 4147 999 1688 3877 3886 317 1541 1743 4302 2958 1322 1959 4470 2856 4046 604 2484 4669 24 4648 4851 4425 493...

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
1
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 5001 numbers

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 0ms
memory: 3912kb

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: 1ms
memory: 3928kb

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:

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 1st numbers differ - expected: '994748608', found: '0'

Subtask #4:

score: 0
Wrong Answer

Test #71:

score: 0
Wrong Answer
time: 0ms
memory: 3564kb

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:

1

result:

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

Subtask #5:

score: 0
Wrong Answer

Test #101:

score: 0
Wrong Answer
time: 1ms
memory: 3932kb

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:

1

result:

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

Subtask #6:

score: 0
Wrong Answer

Test #131:

score: 0
Wrong Answer
time: 1ms
memory: 3860kb

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:

0

result:

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

Subtask #7:

score: 0
Skipped

Dependency #4:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%