QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#494319#9141. Array Spreaducup-team052#WA 1ms3900kbC++231.6kb2024-07-27 15:13:442024-07-27 15:13:45

Judging History

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

  • [2024-09-18 18:58:44]
  • hack成功,自动添加数据
  • (/hack/840)
  • [2024-09-18 18:53:02]
  • hack成功,自动添加数据
  • (/hack/839)
  • [2024-07-29 03:53:23]
  • hack成功,自动添加数据
  • (/hack/753)
  • [2024-07-29 03:51:16]
  • hack成功,自动添加数据
  • (/hack/752)
  • [2024-07-29 03:50:24]
  • hack成功,自动添加数据
  • (/hack/751)
  • [2024-07-29 03:48:52]
  • hack成功,自动添加数据
  • (/hack/750)
  • [2024-07-27 15:13:45]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3900kb
  • [2024-07-27 15:13:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int md = 998244353;

inline int mul(int x, int y) {
	return 1ull * x * y % md;
}

inline int fpow(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		y >>= 1; x = mul(x, x);
	}
	return ans;
}

const int N = 2005;

vector <int> vec[N];
int l[N], r[N], b[N], mxr[N], mnr[N];
int T, n, m, ans1, ans2;

int main() {
	scanf("%d", &T);
	while (T--) {
		memset(mxr, 0, sizeof(mxr));
		memset(mnr, 0x3f, sizeof(mnr));
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= m; i++) {
			scanf("%d%d", &l[i], &r[i]);
			b[i] = l[i];
			vec[i].clear();
		}
		sort(b + 1, b + m + 1);
		for (int i = 1; i <= m; i++) {
			l[i] = lower_bound(b + 1, b + m + 1, l[i]) - b;
			r[i] = upper_bound(b + 1, b + m + 1, r[i]) - b - 1;
			vec[l[i]].push_back(r[i]);
		}
		for (int i = 1; i <= m; i++) {
			mxr[i] = mxr[i - 1];
			for (auto j : vec[i]) mxr[i] = max(mxr[i], j);
		}
		for (int i = m; i >= 1; i--) {
			mnr[i] = mnr[i + 1];
			for (auto j : vec[i]) mnr[i] = min(mnr[i], j);
		}
		ans1 = ans2 = 1;
		for (int i = 1; i <= m; i++) {
			// l[i], r[i]
			int now1 = l[i] - 1, now2 = r[i], cnt1 = 0, cnt2 = 1;
			while (1) {
				while (now1 < now2) {
					if (mxr[now1 + 1] > now1) {
						++cnt1;
						now1 = mxr[now1 + 1];
					} else break;
				}
				if (now1 < now2) break;
				if (cnt2 * ans2 > cnt1 * ans1) {
					ans1 = cnt2;
					ans2 = cnt1;
				}
				if (mnr[now2 + 1] == 0x3f3f3f3f) break;
				now2 = mnr[now2 + 1]; ++cnt2;
			}
		}
		int ans = mul(ans1, fpow(ans2, md - 2));
		printf("%d\n", ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1
2
499122178

result:

ok 3 number(s): "1 2 499122178"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

2000
1000000000 1
259923446 367011266
1000000000 1
882434225 971573327
1000000000 1
41585677 470369580
1000000000 1
371902212 947250194
1000000000 1
787209148 924205796
1000000000 1
259074809 960876164
1000000000 1
148079314 188254573
1000000000 1
940091047 948318624
1000000000 1
40636497 743979446
...

output:

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

result:

ok 2000 numbers

Test #3:

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

input:

1000
1000000000 5
575330909 661595447
708422488 913945134
658050911 930246647
786571892 904549453
851755566 969150871
1000000000 2
198072104 844159589
8876188 644559580
1000000000 2
740802634 976972118
783909534 898449184
1000000000 2
871819537 941611957
465883854 640988372
1000000000 1
99458969 462...

output:

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

result:

wrong answer 32nd numbers differ - expected: '1', found: '2'