QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#382267#5349. 密钥bachbeo2007100 ✓210ms164576kbC++232.0kb2024-04-08 10:04:152024-04-08 10:04:16

Judging History

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

  • [2024-04-08 10:04:16]
  • 评测
  • 测评结果:100
  • 用时:210ms
  • 内存:164576kb
  • [2024-04-08 10:04:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn=2e7+5;
int p[maxn];
int seed, n, k, S;
int getrand() {
	seed = ((seed * 12321) ^ 9999) % 32768;
	return seed;
}
void generateData() {
	cin >> 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 cnt[maxn*2],sum[maxn];
int CalA(int s){
    int cur=0,num=0;
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+(p[i]?1:-1);
        if(p[i]){
            cnt[sum[i]+maxn]++;
            num+=(sum[i]>0);
        }
    }
    int res=0;
    for(int i=1;i<=n;i++){
        if(p[i]){
            cur++;
            num-=cnt[cur+maxn];
        }
        else{
            num+=cnt[cur+maxn];
            cur--;
        }
        if(p[i]){
            cnt[-1+cur+maxn]++;cnt[sum[i]+maxn]--;
            if(sum[i]>cur) num--;
        }
        if(num==s && !p[i]) res=i;
    }
    for(int i=1;i<=n;i++){
        if(p[i]) cnt[sum[i]-1+maxn]--;
    }
    return res;
}
int CalB(int s){
    int cur=0,num=-1;
    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+(p[i]?-1:1);
        if(!p[i]){
            cnt[sum[i]+maxn]++;
            num+=(sum[i]>0);
        }
    }
    int res=0;
    for(int i=1;i<=n;i++){
        if(!p[i]){
            cur++;
            num-=cnt[cur+maxn];
        }
        else{
            num+=cnt[cur+maxn];
            cur--;
        }
        if(!p[i]){
            cnt[1+cur+maxn]++;cnt[sum[i]+maxn]--;
            if(sum[i]<=cur) num++;
        }
        if(num==s && !p[i]) res=i;
    }
    for(int i=1;i<=n;i++){
        if(!p[i]) cnt[sum[i]+1+maxn]--;
    }
    return res;
}
int main() {
	generateData();
    cout << CalA(0) << '\n' << CalA(S) << '\n' << CalB(S) << '\n';
	return 0;
}

詳細信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 85472kb

input:

5
1113
1

output:

1
2
7

result:

points 1.0 ok

Test #2:

score: 10
Accepted
time: 0ms
memory: 84824kb

input:

30
4567
15

output:

53
57
57

result:

points 1.0 ok

Test #3:

score: 10
Accepted
time: 3ms
memory: 85428kb

input:

900
9876
123

output:

1793
1307
488

result:

points 1.0 ok

Test #4:

score: 10
Accepted
time: 0ms
memory: 85852kb

input:

60000
5566
60000

output:

120001
8
120001

result:

points 1.0 ok

Test #5:

score: 10
Accepted
time: 11ms
memory: 86732kb

input:

99999
9988
50000

output:

199993
1
3

result:

points 1.0 ok

Test #6:

score: 10
Accepted
time: 46ms
memory: 100996kb

input:

2000000
3479
1234567

output:

4000001
246933
3753076

result:

points 1.0 ok

Test #7:

score: 10
Accepted
time: 114ms
memory: 125640kb

input:

5000000
1010
999

output:

9999996
9994668
5329

result:

points 1.0 ok

Test #8:

score: 10
Accepted
time: 170ms
memory: 148176kb

input:

8000000
8888
888888

output:

15999988
1777780
14222219

result:

points 1.0 ok

Test #9:

score: 10
Accepted
time: 201ms
memory: 156364kb

input:

9000000
9753
3333333

output:

17999996
666669
17333328

result:

points 1.0 ok

Test #10:

score: 10
Accepted
time: 210ms
memory: 164576kb

input:

10000000
10000
7142857

output:

19999994
5714287
14285708

result:

points 1.0 ok

Extra Test:

score: 0
Extra Test Passed