QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#290602#5349. 密钥MoRanSky100 ✓171ms238152kbC++232.0kb2023-12-25 06:02:182023-12-25 06:02:19

Judging History

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

  • [2023-12-25 06:02:19]
  • 评测
  • 测评结果:100
  • 用时:171ms
  • 内存:238152kb
  • [2023-12-25 06:02:18]
  • 提交

answer

// Skyqwq
#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }

template <typename T> void inline read(T &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
    x *= f;
}

const int N = 2e7 + 5, M = 1e7 + 2;

int p[20000005], a[N], s[N];
int seed, n, k, S;
int getrand()
{
	seed = ((seed * 12321) ^ 9999) % 32768;
	return seed;
}
void generateData()
{
	scanf("%d%d%d",&k,&seed,&S);
	int t = 0;
	n = k * 2 + 1;
	memset(p, 0, sizeof(p));
	for (int i = 1; i <= n; i++)
	{
		p[i] = (getrand() / 128) % 2;
		t += p[i];
	}
	int i = 1;
	while (t > k)
	{
		while (p[i] == 0)
			i++;
		p[i] = 0;
		t--;
	}
	while (t < k)
	{
		while (p[i] == 1)
			i++;
		p[i] = 1;
		t++;
	}
}

int ans[4];

void inline work12() {
	for (int i = 1; i <= n; i++) {
		int v = p[i] ? 1 : -1;
		a[i] = v + a[i - 1];
		if (p[i]) s[a[i] + M]++;
	}
	for (int i = N - 2; i >= 0; i--)
		s[i] += s[i + 1];
	for (int i = 1; i <= n; i++) {
		if (p[i]) {
			s[a[i] + M]--;
			a[i]--;
			continue;
		}
		int o = s[a[i] + 1 + M];
		if (o == 0) ans[1] = i;
		if (o == S) ans[2] = i;
	}
}

void inline work3() {
	memset(s, 0, sizeof s);
	for (int i = 1; i <= n; i++) {
		int v = p[i] ? -1 : 1;
		a[i] = v + a[i - 1];
		if (!p[i]) s[a[i] + M]++;
	}
	for (int i = N - 2; i >= 0; i--)
		s[i] += s[i + 1];
	for (int i = 1; i <= n; i++) {
		if (!p[i]) {
			int o = s[a[i] + 1 + M];
			if (o == S) ans[3] = i;	
		}
		if (!p[i]) {
			a[i]++;
			s[a[i] + M]++;
		}	
	}
}

int main()
{	
	generateData();
	work12();
	work3();
	printf("%d\n%d\n%d\n", ans[1], ans[2], ans[3]);
	return 0;
}

詳細信息

Test #1:

score: 10
Accepted
time: 19ms
memory: 160632kb

input:

5
1113
1

output:

1
2
7

result:

points 1.0 ok

Test #2:

score: 10
Accepted
time: 23ms
memory: 161796kb

input:

30
4567
15

output:

53
57
57

result:

points 1.0 ok

Test #3:

score: 10
Accepted
time: 27ms
memory: 160600kb

input:

900
9876
123

output:

1793
1307
488

result:

points 1.0 ok

Test #4:

score: 10
Accepted
time: 28ms
memory: 161276kb

input:

60000
5566
60000

output:

120001
8
120001

result:

points 1.0 ok

Test #5:

score: 10
Accepted
time: 32ms
memory: 162512kb

input:

99999
9988
50000

output:

199993
1
3

result:

points 1.0 ok

Test #6:

score: 10
Accepted
time: 47ms
memory: 176824kb

input:

2000000
3479
1234567

output:

4000001
246933
3753076

result:

points 1.0 ok

Test #7:

score: 10
Accepted
time: 94ms
memory: 201324kb

input:

5000000
1010
999

output:

9999996
9994668
5329

result:

points 1.0 ok

Test #8:

score: 10
Accepted
time: 110ms
memory: 223252kb

input:

8000000
8888
888888

output:

15999988
1777780
14222219

result:

points 1.0 ok

Test #9:

score: 10
Accepted
time: 171ms
memory: 231512kb

input:

9000000
9753
3333333

output:

17999996
666669
17333328

result:

points 1.0 ok

Test #10:

score: 10
Accepted
time: 147ms
memory: 238152kb

input:

10000000
10000
7142857

output:

19999994
5714287
14285708

result:

points 1.0 ok

Extra Test:

score: 0
Extra Test Passed