QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#742499#5349. 密钥KiharaTouma100 ✓129ms162212kbC++231.7kb2024-11-13 16:43:112024-11-13 16:43:14

Judging History

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

  • [2024-11-13 16:43:14]
  • 评测
  • 测评结果:100
  • 用时:129ms
  • 内存:162212kb
  • [2024-11-13 16:43:11]
  • 提交

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(le == k - S){
                ansB = 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;
    }
    -- ansB;
    if(!ansB){
        ansB = 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: 10
Accepted
time: 6ms
memory: 85068kb

input:

5
1113
1

output:

1
2
7

result:

points 1.0 ok

Test #2:

score: 10
Accepted
time: 4ms
memory: 85608kb

input:

30
4567
15

output:

53
57
57

result:

points 1.0 ok

Test #3:

score: 10
Accepted
time: 6ms
memory: 85508kb

input:

900
9876
123

output:

1793
1307
488

result:

points 1.0 ok

Test #4:

score: 10
Accepted
time: 8ms
memory: 86364kb

input:

60000
5566
60000

output:

120001
8
120001

result:

points 1.0 ok

Test #5:

score: 10
Accepted
time: 10ms
memory: 85500kb

input:

99999
9988
50000

output:

199993
1
3

result:

points 1.0 ok

Test #6:

score: 10
Accepted
time: 33ms
memory: 100800kb

input:

2000000
3479
1234567

output:

4000001
246933
3753076

result:

points 1.0 ok

Test #7:

score: 10
Accepted
time: 64ms
memory: 125276kb

input:

5000000
1010
999

output:

9999996
9994668
5329

result:

points 1.0 ok

Test #8:

score: 10
Accepted
time: 111ms
memory: 149808kb

input:

8000000
8888
888888

output:

15999988
1777780
14222219

result:

points 1.0 ok

Test #9:

score: 10
Accepted
time: 123ms
memory: 158088kb

input:

9000000
9753
3333333

output:

17999996
666669
17333328

result:

points 1.0 ok

Test #10:

score: 10
Accepted
time: 129ms
memory: 162212kb

input:

10000000
10000
7142857

output:

19999994
5714287
14285708

result:

points 1.0 ok

Extra Test:

score: 0
Extra Test Passed