QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#272730#6753. Mediansmobbb#WA 1ms5564kbC++171.3kb2023-12-02 18:54:072023-12-02 18:54:08

Judging History

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

  • [2023-12-02 18:54:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5564kb
  • [2023-12-02 18:54:07]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int P = 998244353;

const int N = 1e7 + 7;

const int mod = 1e9 + 7;

int n;
int a[N];
int p[N];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	cin >> n >> a[0];
	for (int i = 1;i <= n;i++){
		a[i] = (a[i - 1] % (mod + 2) * P % (mod + 2) + mod) % (mod + 2);
		p[i] = i;
	}
	for (int i = 1;i <= n;i++){
		swap(p[i],p[a[i] % i + 1]);
	}
	
	int res = 0;
	int cur = 1;
	// l.b x r.b
	set<int> r;
	set<int,greater<>> l;

	for (int i = 1;i <= n;i++){
		(cur *= 19) % P;
		if (l.empty()){
			l.insert(p[i]);
		}else{
			if (*l.begin() < p[i]){
				r.insert(p[i]);
				if (r.size() - l.size() > 1){
					l.insert(*r.begin());
					r.erase(r.begin());
				}
			}else{
				l.insert(p[i]);
				if (l.size() - r.size() > 1){
					r.insert(*l.begin());
					l.erase(l.begin());
				}
			}
		}
		if (l.size() == r.size()){
			(res += *l.begin() % P * cur % P) %= P;
			//cout << *l.begin() << endl;
		}else{
			if (l.size() > r.size()){
				(res += *l.begin() % P * cur % P) %= P;	
				//cout << *l.begin() << endl;
			}else{
				(res += *r.begin() % P * cur % P) %= P;	
				//cout << *r.begin() << endl;
			}
		}
	}

	cout << res << endl;




	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5504kb

input:

5 0

output:

7703113

result:

ok 1 number(s): "7703113"

Test #2:

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

input:

5 1

output:

7840977

result:

ok 1 number(s): "7840977"

Test #3:

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

input:

2 1361955

output:

399

result:

ok 1 number(s): "399"

Test #4:

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

input:

4 207579012

output:

274740

result:

ok 1 number(s): "274740"

Test #5:

score: 0
Accepted
time: 0ms
memory: 5516kb

input:

8 628145516

output:

783389330

result:

ok 1 number(s): "783389330"

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 5480kb

input:

16 376140462

output:

525275665

result:

wrong answer 1st numbers differ - expected: '772072366', found: '525275665'