QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#133539 | #4936. Shopping Changes | Delay_for_five_minutes# | WA | 46ms | 8632kb | C++14 | 1.6kb | 2023-08-02 10:49:30 | 2023-08-02 10:50:34 |
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];
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: 2ms
memory: 5840kb
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: 2ms
memory: 7564kb
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: 7132kb
input:
1 1 589284012 1 767928734
output:
0
result:
ok single line: '0'
Test #4:
score: -100
Wrong Answer
time: 46ms
memory: 8632kb
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:
-897054591698 -899799628573 -896076047403 -896188510496 -901842714297 -896832657763 -898973213449 -897721909070 -898684861253 -897313870013 -901019687686 -898767635285 -902280424154 -897048955085 -902313794959 -898037655966 -898523115375 -904538122481 -897576546278 -893996744818 -895956459259 -89964...
result:
wrong answer 1st lines differ - expected: '24802338', found: '-897054591698'