QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#272701 | #6753. Medians | mobbb# | WA | 1ms | 5572kb | C++17 | 1.3kb | 2023-12-02 18:43:32 | 2023-12-02 18:43:34 |
Judging History
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) % (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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5572kb
input:
5 0
output:
7703113
result:
ok 1 number(s): "7703113"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5508kb
input:
5 1
output:
7840977
result:
ok 1 number(s): "7840977"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5568kb
input:
2 1361955
output:
399
result:
ok 1 number(s): "399"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5484kb
input:
4 207579012
output:
274740
result:
ok 1 number(s): "274740"
Test #5:
score: 0
Accepted
time: 0ms
memory: 5460kb
input:
8 628145516
output:
783389330
result:
ok 1 number(s): "783389330"
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 5472kb
input:
16 376140462
output:
3520008724
result:
wrong answer 1st numbers differ - expected: '772072366', found: '3520008724'