QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#272731 | #6753. Medians | mobbb# | TL | 1638ms | 137628kb | C++17 | 1.3kb | 2023-12-02 18:54:32 | 2023-12-02 18:54:32 |
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 + 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: 5472kb
input:
5 0
output:
7703113
result:
ok 1 number(s): "7703113"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5504kb
input:
5 1
output:
7840977
result:
ok 1 number(s): "7840977"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5440kb
input:
2 1361955
output:
399
result:
ok 1 number(s): "399"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5480kb
input:
4 207579012
output:
274740
result:
ok 1 number(s): "274740"
Test #5:
score: 0
Accepted
time: 1ms
memory: 5460kb
input:
8 628145516
output:
783389330
result:
ok 1 number(s): "783389330"
Test #6:
score: 0
Accepted
time: 0ms
memory: 5468kb
input:
16 376140462
output:
772072366
result:
ok 1 number(s): "772072366"
Test #7:
score: 0
Accepted
time: 0ms
memory: 5460kb
input:
32 883515280
output:
822906393
result:
ok 1 number(s): "822906393"
Test #8:
score: 0
Accepted
time: 1ms
memory: 5488kb
input:
64 186969585
output:
536948870
result:
ok 1 number(s): "536948870"
Test #9:
score: 0
Accepted
time: 1ms
memory: 5576kb
input:
128 762888635
output:
914896632
result:
ok 1 number(s): "914896632"
Test #10:
score: 0
Accepted
time: 1ms
memory: 5516kb
input:
256 326402539
output:
816864808
result:
ok 1 number(s): "816864808"
Test #11:
score: 0
Accepted
time: 1ms
memory: 5464kb
input:
512 98152102
output:
792934555
result:
ok 1 number(s): "792934555"
Test #12:
score: 0
Accepted
time: 0ms
memory: 5496kb
input:
1024 158176572
output:
187304261
result:
ok 1 number(s): "187304261"
Test #13:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
2048 61402883
output:
881629018
result:
ok 1 number(s): "881629018"
Test #14:
score: 0
Accepted
time: 1ms
memory: 5700kb
input:
4096 127860889
output:
926052991
result:
ok 1 number(s): "926052991"
Test #15:
score: 0
Accepted
time: 2ms
memory: 5900kb
input:
8192 9580638
output:
18767865
result:
ok 1 number(s): "18767865"
Test #16:
score: 0
Accepted
time: 0ms
memory: 6468kb
input:
16384 570870044
output:
676635475
result:
ok 1 number(s): "676635475"
Test #17:
score: 0
Accepted
time: 5ms
memory: 9196kb
input:
32768 646139319
output:
121314798
result:
ok 1 number(s): "121314798"
Test #18:
score: 0
Accepted
time: 16ms
memory: 9088kb
input:
65536 178509022
output:
518784793
result:
ok 1 number(s): "518784793"
Test #19:
score: 0
Accepted
time: 37ms
memory: 12644kb
input:
131072 484027666
output:
783563468
result:
ok 1 number(s): "783563468"
Test #20:
score: 0
Accepted
time: 93ms
memory: 21904kb
input:
262144 61263304
output:
560815556
result:
ok 1 number(s): "560815556"
Test #21:
score: 0
Accepted
time: 238ms
memory: 39728kb
input:
524288 841082555
output:
478037004
result:
ok 1 number(s): "478037004"
Test #22:
score: 0
Accepted
time: 622ms
memory: 72780kb
input:
1048576 558212774
output:
145045199
result:
ok 1 number(s): "145045199"
Test #23:
score: 0
Accepted
time: 1638ms
memory: 137628kb
input:
2097152 940563715
output:
267114566
result:
ok 1 number(s): "267114566"
Test #24:
score: -100
Time Limit Exceeded
input:
4194304 26389620
output:
535216368