QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133546 | #4936. Shopping Changes | Delay_for_five_minutes# | WA | 72ms | 10200kb | C++14 | 1.6kb | 2023-08-02 10:58:07 | 2023-08-02 10:58:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+3;
int n,m,a[N];
vector<int> b[N];
int buc[N*3],tot=0;
struct bit{
int c[N*3];
void upd(int x,int y){
for(;x<=tot;x+=x&-x)c[x]+=y;
}
int qry(int x){
int r=0;
for(;x;x-=x&-x)r+=c[x];
return r;
}
}c1,c2;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;++i){
cin>>a[i];
buc[++tot]=a[i];
}
for(int i=1;i<=m;++i){
int k;
cin>>k;
b[i].resize(k);
for(int j=0;j<k;++j){
cin>>b[i][j];
buc[++tot]=b[i][j];
}
}
sort(buc+1,buc+tot+1),tot=unique(buc+1,buc+tot+1)-buc-1;
for(int i=1;i<=n;++i)a[i]=lower_bound(buc+1,buc+tot+1,a[i])-buc;
for(int i=1;i<=m;++i)
for(int& x:b[i])
x=lower_bound(buc+1,buc+tot+1,x)-buc;
ll s1=0;
for(int i=1;i<=n;++i){
s1+=i-1-c1.qry(a[i]-1);
c1.upd(a[i],1);
}
for(int i=1;i<=m;++i){
int k=b[i].size();
ll s2=0;
for(int j=0;j<k;++j){
s2+=j-c2.qry(b[i][j]);
c2.upd(b[i][j],1);
}
ll s3=0,now=0;
for(int j=0;j<k;++j)
now+=n-c1.qry(b[i][j]);
s3=now;
for(int j=0;j<k;++j){
now+=c1.qry(b[i][j]-1);
now-=n-c1.qry(b[i][j]);
s3=min(s3,now);
}
//cout<<s1<<' '<<s2<<' '<<s3<<'\n';
cout<<s1+s2+s3<<'\n';
for(int j=0;j<k;++j)c2.upd(b[i][j],-1);
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6784kb
input:
3 3 5 6 7 6 2 3 4 8 9 10 2 100 99 3 5 6 7
output:
0 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 6204kb
input:
3 2 7 6 5 6 2 3 4 8 9 10 6 10 9 8 4 3 2
output:
3 27
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 2ms
memory: 7828kb
input:
1 1 589284012 1 767928734
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 41ms
memory: 9104kb
input:
10000 9999 298772847 712804102 869795012 527998188 804246450 598105371 843966934 639805471 937482040 887551242 254734680 188704975 17408126 626523673 553956319 697723205 231690822 637079761 232393146 377026277 962223856 338922458 912529500 710873344 942955137 51167037 195729799 529674367 990599310 4...
output:
24802338 24830913 24857654 24813132 24846150 24785558 24857315 24805175 24862714 24785339 24804999 24780907 24808009 24798987 24958122 24781372 24772291 24846071 24953540 24778276 24778689 24979527 24770012 24892097 24776909 24865295 24821506 24772586 24800432 24891424 24864488 24820312 24801522 248...
result:
ok 9999 lines
Test #5:
score: -100
Wrong Answer
time: 72ms
memory: 10200kb
input:
42320 25000 977178721 305456426 916831455 324594376 259922325 798438534 906876242 353428436 459214642 504133134 734517252 944888626 929971853 735313273 285979369 866298401 385768124 918185862 811827492 3054135 190006456 852394509 784943097 903969029 4089198 931644108 916374905 942243264 383987411 45...
output:
448869836 448857082 449001852 448984954 448766023 449088371 448753000 448813228 448791233 448952236 448991582 448762189 449564835 448895405 448773617 448827148 448822398 448871141 448785181 448915023 448786816 448758119 448930421 449164517 448765913 448826223 448791835 448895669 448789205 448791198 ...
result:
wrong answer 1st lines differ - expected: '448869835', found: '448869836'