QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#424152#6753. MediansHUY1#AC ✓1675ms259868kbC++141.6kb2024-05-28 23:33:582024-05-28 23:33:58

Judging History

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

  • [2024-05-28 23:33:58]
  • 评测
  • 测评结果:AC
  • 用时:1675ms
  • 内存:259868kb
  • [2024-05-28 23:33:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e7+10;
const ll mod=998244353;
const ll sb=1e9;
ll n,a[N],p[N];
ll qpow(ll a,ll b){
    ll ans=1,tmp=a;
    while(b){
        if(b&1) ans=(ans*tmp)%mod;
        tmp=(tmp*tmp)%mod;
        ans%=mod;
        b>>=1;
    }
    return ans;
}
ll work(ll k,ll i){
    return (k%mod)*qpow(19,i)%mod;
}
void solve(){
    cin>>n>>a[0];
    for(int i=1;i<=n;i++){
        a[i]= (a[i-1]* mod%(sb+9)+sb+7 )%(sb+9);
        p[i]=i;
    }
    for(int i=1;i<=n;i++){
        swap(p[i],p[a[i]%i+1]);
    }
    //cout<<66<<endl;
    ll ans=0;
    priority_queue<ll,vector<ll>,less<ll>>q1;//
    priority_queue<ll,vector<ll>,greater<ll>>q2;//
    q1.push(-1e12),q2.push(1e12);
    for(int i=1;i<=n;i++){
        if(i==1) ans=(ans+work(p[i],i))%mod,q1.push(p[i]);
        else{

            if(p[i]>q2.top()) q2.push(p[i]);
            else q1.push(p[i]);
            if(q1.size()!=q2.size()){
                if(q1.size()==q2.size()+2){
                   ll hy=q1.top();
                   q1.pop();
                   q2.push(hy);
                }else if(q2.size()==q1.size()+1){
                    ll hy=q2.top();
                    q2.pop();
                    q1.push(hy);
                }

            }
            ans=(ans+work(q1.top(),i)%mod)%mod;

        }
        //cout<<p[i]<<" "<<q1.top()<<endl;

    }
    cout<<ans<<endl;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5628kb

input:

5 0

output:

7703113

result:

ok 1 number(s): "7703113"

Test #2:

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

input:

5 1

output:

7840977

result:

ok 1 number(s): "7840977"

Test #3:

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

input:

2 1361955

output:

399

result:

ok 1 number(s): "399"

Test #4:

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

input:

4 207579012

output:

274740

result:

ok 1 number(s): "274740"

Test #5:

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

input:

8 628145516

output:

783389330

result:

ok 1 number(s): "783389330"

Test #6:

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

input:

16 376140462

output:

772072366

result:

ok 1 number(s): "772072366"

Test #7:

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

input:

32 883515280

output:

822906393

result:

ok 1 number(s): "822906393"

Test #8:

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

input:

64 186969585

output:

536948870

result:

ok 1 number(s): "536948870"

Test #9:

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

input:

128 762888635

output:

914896632

result:

ok 1 number(s): "914896632"

Test #10:

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

input:

256 326402539

output:

816864808

result:

ok 1 number(s): "816864808"

Test #11:

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

input:

512 98152102

output:

792934555

result:

ok 1 number(s): "792934555"

Test #12:

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

input:

1024 158176572

output:

187304261

result:

ok 1 number(s): "187304261"

Test #13:

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

input:

2048 61402883

output:

881629018

result:

ok 1 number(s): "881629018"

Test #14:

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

input:

4096 127860889

output:

926052991

result:

ok 1 number(s): "926052991"

Test #15:

score: 0
Accepted
time: 2ms
memory: 5880kb

input:

8192 9580638

output:

18767865

result:

ok 1 number(s): "18767865"

Test #16:

score: 0
Accepted
time: 2ms
memory: 6184kb

input:

16384 570870044

output:

676635475

result:

ok 1 number(s): "676635475"

Test #17:

score: 0
Accepted
time: 3ms
memory: 6196kb

input:

32768 646139319

output:

121314798

result:

ok 1 number(s): "121314798"

Test #18:

score: 0
Accepted
time: 10ms
memory: 6532kb

input:

65536 178509022

output:

518784793

result:

ok 1 number(s): "518784793"

Test #19:

score: 0
Accepted
time: 12ms
memory: 9192kb

input:

131072 484027666

output:

783563468

result:

ok 1 number(s): "783563468"

Test #20:

score: 0
Accepted
time: 31ms
memory: 13820kb

input:

262144 61263304

output:

560815556

result:

ok 1 number(s): "560815556"

Test #21:

score: 0
Accepted
time: 78ms
memory: 23364kb

input:

524288 841082555

output:

478037004

result:

ok 1 number(s): "478037004"

Test #22:

score: 0
Accepted
time: 157ms
memory: 34400kb

input:

1048576 558212774

output:

145045199

result:

ok 1 number(s): "145045199"

Test #23:

score: 0
Accepted
time: 316ms
memory: 66112kb

input:

2097152 940563715

output:

267114566

result:

ok 1 number(s): "267114566"

Test #24:

score: 0
Accepted
time: 647ms
memory: 121516kb

input:

4194304 26389620

output:

535216368

result:

ok 1 number(s): "535216368"

Test #25:

score: 0
Accepted
time: 1377ms
memory: 234564kb

input:

8388608 579113528

output:

926081338

result:

ok 1 number(s): "926081338"

Test #26:

score: 0
Accepted
time: 1655ms
memory: 259476kb

input:

10000000 496147999

output:

872799419

result:

ok 1 number(s): "872799419"

Test #27:

score: 0
Accepted
time: 1666ms
memory: 259716kb

input:

10000000 925801172

output:

676521567

result:

ok 1 number(s): "676521567"

Test #28:

score: 0
Accepted
time: 1640ms
memory: 259868kb

input:

10000000 837151740

output:

617759049

result:

ok 1 number(s): "617759049"

Test #29:

score: 0
Accepted
time: 1665ms
memory: 258704kb

input:

10000000 70301164

output:

413391579

result:

ok 1 number(s): "413391579"

Test #30:

score: 0
Accepted
time: 1643ms
memory: 259456kb

input:

10000000 656585275

output:

505441893

result:

ok 1 number(s): "505441893"

Test #31:

score: 0
Accepted
time: 1654ms
memory: 259140kb

input:

10000000 285845005

output:

465986348

result:

ok 1 number(s): "465986348"

Test #32:

score: 0
Accepted
time: 1675ms
memory: 258952kb

input:

10000000 902071050

output:

964328151

result:

ok 1 number(s): "964328151"