QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#413672 | #6753. Medians | Arnold_6 | RE | 0ms | 0kb | C++17 | 977b | 2024-05-17 20:52:17 | 2024-05-17 20:52:19 |
answer
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int n;
int a[10000010],p[10000010];
int mid;
LL ans,qp=19;
priority_queue <int> q1,q2;
int main(){
scanf("%d%d",&n,&a[0]);
for(int i=1;i<=n;++i) p[i]=i;
for(int i=1;i<=n;++i) a[i]=(1ll*a[i-1]*998244353+1000000007)%1000000009;
for(int i=1;i<=n;++i) swap(p[i],p[a[i]%i+1]);
mid=p[1];
ans=mid*19%998244353;
for(int i=2;i<=n;++i){
qp=qp*19%998244353;
if(i&1){
if(p[i]>-q2.top()) q2.push(-p[i]),mid=-q2.top(),q2.pop();
else if(p[i]>q1.top()) mid=p[i];
else q1.push(p[i]),mid=q1.top(),q1.pop();
ans=(1ll*ans+mid*qp%998244353)%998244353;
}
else{
if(p[i]>mid) q2.push(-p[i]),q1.push(mid);
else q1.push(p[i]),q2.push(-mid);
ans=(1ll*ans+q1.top()*qp%998244353)%998244353;
}
}
printf("%lld",ans);
system("pause");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
5 0