QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#439858 | #8712. Flooding Wall | A_zjzj | 12 | 783ms | 34960kb | C++17 | 2.4kb | 2024-06-12 19:46:05 | 2024-06-12 19:46:06 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned ll;
const int N=5e5+10,mod=1e9+7,inv[3]={0,1,(mod+1)/2};
int n,pw,a[2][N],t[N];
tuple<int,int,int>p[N+N];
namespace SGT{
int t[N<<2],mul[N<<2];
void pushup(int rt){
t[rt]=(t[rt<<1]+t[rt<<1|1])%mod;
}
void pushmul(int rt,int x){
t[rt]=1ll*t[rt]*x%mod;
mul[rt]=1ll*mul[rt]*x%mod;
}
void pushdown(int rt){
if(mul[rt]^1){
pushmul(rt<<1,mul[rt]);
pushmul(rt<<1|1,mul[rt]);
mul[rt]=1;
}
}
void build(int l=1,int r=n,int rt=1){
mul[rt]=1;
if(l==r)return t[rt]=pw,void();
int mid=(l+r)>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
pushup(rt);
}
void update(int L,int R,int x,int l=1,int r=n,int rt=1){
if(L<=l&&r<=R)return pushmul(rt,x);
int mid=(l+r)>>1;
pushdown(rt);
if(L<=mid)update(L,R,x,l,mid,rt<<1);
if(mid<R)update(L,R,x,mid+1,r,rt<<1|1);
pushup(rt);
}
int query(int L,int R,int l=1,int r=n,int rt=1){
if(L<=l&&r<=R)return t[rt];
int mid=(l+r)>>1,s=0;
pushdown(rt);
if(L<=mid)s+=query(L,R,l,mid,rt<<1);
if(mid<R)s+=query(L,R,mid+1,r,rt<<1|1);
return s%mod;
}
}
int calc(){
SGT::build();
int ans=0;
fill(t+1,t+1+n,2);
for(int i=1;i<=n+n;i++){
auto [val,c,id]=p[i];
ans=(ans+1ll*SGT::query(id,n)*inv[t[id]]%mod*val)%mod;
SGT::update(id,n,inv[t[id]]*(t[id]-1ll)%mod);
t[id]--;
// debug(c,id,ans);
}
// debug("calc",ans);
return ans;
}
int solve(){
int ans=0,res=pw;
fill(t+1,t+1+n,2);
for(int i=1;i<=n+n&&res;i++){
auto [val,c,id]=p[i];
res=1ll*res*inv[t[id]]%mod;
ans=(ans+1ll*res*val%mod*n)%mod;
res=res*--t[id]%mod;
// debug(c,id,ans);
}
return ans;
}
int main(){
scanf("%d",&n);
for(int i=pw=1;i<=n;i++)(pw*=2)%=mod;
for(int c:{0,1}){
for(int i=1;i<=n;i++){
scanf("%d",&a[c][i]);
p[i+c*n]={a[c][i],c,i};
}
}
sort(p+1,p+1+n+n),reverse(p+1,p+1+n+n);
int ans=calc();
for(int c:{0,1})reverse(a[c]+1,a[c]+1+n);
(ans+=calc())%=mod;
(ans+=mod-solve())%=mod;
for(int c:{0,1}){
for(int i=1;i<=n;i++){
ans=(ans+1ll*(mod-a[c][i])*pw%mod*inv[2])%mod;
}
}
cout<<ans<<endl;
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 8
Accepted
time: 2ms
memory: 13936kb
input:
4 1 1 1 1 2 2 2 2
output:
6
result:
ok single line: '6'
Test #2:
score: 0
Accepted
time: 0ms
memory: 14008kb
input:
10 1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1
output:
21116
result:
ok single line: '21116'
Test #3:
score: 0
Accepted
time: 2ms
memory: 14060kb
input:
1 1 2
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 2ms
memory: 14068kb
input:
2 1 1 2 2
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 13932kb
input:
3 1 1 1 2 2 2
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 1ms
memory: 13992kb
input:
3 1 1 1 3 2 3
output:
3
result:
ok single line: '3'
Test #7:
score: -8
Wrong Answer
time: 1ms
memory: 14060kb
input:
3 2 1 1 3 2 3
output:
10
result:
wrong answer 1st lines differ - expected: '4', found: '10'
Subtask #2:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 1ms
memory: 13812kb
input:
100 948 425 211 688 416 81 356 602 712 954 117 522 797 75 281 491 662 669 78 156 939 526 929 937 916 619 166 777 48 898 449 278 298 714 668 755 679 38 389 602 195 135 672 833 655 541 473 27 596 274 351 353 598 993 837 246 950 99 179 751 481 843 550 195 964 279 806 82 330 599 124 756 649 838 513 625 ...
output:
398638337
result:
wrong answer 1st lines differ - expected: '164439470', found: '398638337'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 12
Accepted
Test #57:
score: 12
Accepted
time: 775ms
memory: 34840kb
input:
500000 1 1 1 1 2 2 2 1 1 1 1 1 2 2 1 1 2 2 2 2 1 2 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 2 1 1 2 2 2 2 1 2 2 2 2 1 2 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 1 2 1 2 1 2 2 1 2 2 2 2 2 2 2 1 1 1 2 2 2 1 1 2 1 2 2 1 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 1 1 1 2 1 2 1 1 2 1 2 1 2 2 1 1 2 1 1 1 1 1 2 2 2 2 2 2 1 2 2 1 1 2 1 2 1...
output:
869044223
result:
ok single line: '869044223'
Test #58:
score: 0
Accepted
time: 767ms
memory: 34960kb
input:
499993 1 1 2 1 1 2 1 1 2 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 1 1 2 2 1 2 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 2 2 1 1 2 2 2 2 2 1 1 2 1 1 2 1 1 2 2 2 1 2 2 1 2 1 1 2 1 1 2 1 1 1 1 2 1 1 1 2 2 1 1 2 1 1 1 2 2 2 2 1 1 2 1 2 1 2 2 1 2 1 1 1 1 2 1 1 2 1 2 2 1 2 2 2 2 2 1 2 2 1 1 1 2 1 1 1 1 2 1 1 1 2 1 1 2 1 1 1...
output:
480826834
result:
ok single line: '480826834'
Test #59:
score: 0
Accepted
time: 783ms
memory: 32932kb
input:
500000 2 2 1 1 2 2 2 1 1 2 2 2 2 2 1 1 1 1 1 2 1 2 1 2 1 2 2 1 1 1 2 1 1 1 1 1 1 2 2 2 2 2 2 2 2 1 2 1 2 1 2 1 1 2 1 1 2 2 2 1 2 2 1 2 2 1 2 2 1 1 1 2 1 1 1 2 2 2 1 1 1 1 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 2 2 1 2 1 1 2 1 2 1 1 2 2 2 1 2 1 2 2 2 2 2 2 1 1 2 2 2 2 1 1 1 1 1 1 2 2 1 1 1 2 1 2 2 2 1 1 1 2 2...
output:
869044223
result:
ok single line: '869044223'
Test #60:
score: 0
Accepted
time: 767ms
memory: 32932kb
input:
499999 2 1 2 2 1 2 1 1 2 1 1 1 2 2 2 1 1 2 2 2 1 1 1 2 2 2 2 2 1 2 2 1 1 2 2 2 2 1 1 2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 1 2 1 2 1 1 1 1 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 1 2 1 1 2 1 1 1 2 2 1 1 2 2 2 2 2 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 2 1 1 2 1 2 1 2 1 2 2 2 1 1...
output:
192864306
result:
ok single line: '192864306'
Subtask #6:
score: 0
Skipped
Dependency #1:
0%