QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#742468#5349. 密钥KiharaTouma70 133ms162048kbC++231.6kb2024-11-13 16:39:542024-11-13 16:39:54

Judging History

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

  • [2024-11-13 16:39:54]
  • 评测
  • 测评结果:70
  • 用时:133ms
  • 内存:162048kb
  • [2024-11-13 16:39:54]
  • 提交

answer

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

const int T = 1e7;
int p[20000005];
int seed, n, k, S;
int pr[20000005];
int buc[20000005];

void solve(){
    int le = 0, nw = 0;
    int ans0, ansS, ansB;
    p[0] = p[n];
    for(int i = 1; i <= n; ++ i){
        pr[i] = pr[i-1] + (p[i] == 1 ? 1 : -1);
        if(p[i] == 1){
            ++ buc[T+pr[i]];
            if(pr[i] > 0){
                ++ le;
            }
        }
    }
    for(int i = 1; i <= n; ++ i){
        if(p[i-1] == 0){
            if(le == 0){
                ans0 = i;
            }
            if(le == S){
                ansS = i;
            }
        }
        if(p[i] == 0){
            le += buc[T+nw];
            -- nw;
        } else {
            ++ nw;
            le -= buc[T+nw];
            -- buc[T+pr[i]];
            if(pr[i]+nw > 0) -- le;
            -- pr[i];
            ++ buc[T+pr[i]];
            if(pr[i]+nw > 0) ++ le;
        }
    }
    -- ans0;
    if(!ans0){
        ans0 = n;
    }
    -- ansS;
    if(!ansS){
        ansS = n;
    }
    printf("%d\n%d\n%d\n", ans0, ansS, ansB);
}

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 main() {
	generateData();
    solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 7
Acceptable Answer
time: 3ms
memory: 85088kb

input:

5
1113
1

output:

1
2
0

result:

points 0.70 ok

Test #2:

score: 7
Acceptable Answer
time: 6ms
memory: 84652kb

input:

30
4567
15

output:

53
57
0

result:

points 0.70 ok

Test #3:

score: 7
Acceptable Answer
time: 0ms
memory: 84352kb

input:

900
9876
123

output:

1793
1307
0

result:

points 0.70 ok

Test #4:

score: 7
Acceptable Answer
time: 4ms
memory: 84988kb

input:

60000
5566
60000

output:

120001
8
0

result:

points 0.70 ok

Test #5:

score: 7
Acceptable Answer
time: 0ms
memory: 86244kb

input:

99999
9988
50000

output:

199993
1
0

result:

points 0.70 ok

Test #6:

score: 7
Acceptable Answer
time: 29ms
memory: 102856kb

input:

2000000
3479
1234567

output:

4000001
246933
0

result:

points 0.70 ok

Test #7:

score: 7
Acceptable Answer
time: 67ms
memory: 125224kb

input:

5000000
1010
999

output:

9999996
9994668
0

result:

points 0.70 ok

Test #8:

score: 7
Acceptable Answer
time: 105ms
memory: 147760kb

input:

8000000
8888
888888

output:

15999988
1777780
0

result:

points 0.70 ok

Test #9:

score: 7
Acceptable Answer
time: 127ms
memory: 156032kb

input:

9000000
9753
3333333

output:

17999996
666669
0

result:

points 0.70 ok

Test #10:

score: 7
Acceptable Answer
time: 133ms
memory: 162048kb

input:

10000000
10000
7142857

output:

19999994
5714287
0

result:

points 0.70 ok