ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#209923 | #3778. 交换乘积 | Allen123456hello | 100 | 197ms | 3240kb | C++11 | 1.2kb | 2024-08-05 10:59:49 | 2024-08-05 12:17:41 |
answer
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
typedef long long LL;
int n;
LL arr[1005],brr[1005],ays[1005],ayd[1005],bys[1005],byd[1005],bye[1005],byy[1005],ans=0;
vector<LL> op;
void fun(){
LL x;
for (int i=2;i<=n;++i){
x=i;
while ((x>1)&&(byy[x]<byy[x-1])){swap(byy[x],byy[x-1]);op.emplace_back(--x);}
}
}
void output(){
bool ok=0;printf("%lu\n",op.size());for (auto &&i : op){if (ok){putchar(' ');}else{ok=1;}printf("%lld",i);}
}
bool acmp(LL x,LL y){return arr[x]<arr[y];}
bool bbbcmp(LL x,LL y){return brr[x]<brr[y];}
bool ccmp(pair<LL,LL> x,pair<LL,LL> y){return x.second<y.second;}
int main(){
scanf("%d",&n);
for (int i=1;i<=n;++i){scanf("%lld",arr+i);ays[i]=i;}for (int i=1;i<=n;++i){scanf("%lld",brr+i);bys[i]=i;}
sort(ays+1,ays+1+n,acmp);sort(bys+1,bys+1+n,bbbcmp);
for (int i=1;i<=n;++i){byd[bys[i]]=i;ayd[ays[i]]=i;}
sort(arr+1,arr+1+n);sort(brr+1,brr+1+n);
for (int i=1;i<=n;++i){bye[byd[i]]=i;}
for (int i=1;i<=n;++i){byy[i]=bye[ayd[i]];}
for (LL i=1;i<=n;++i){ans+=(arr[i]*brr[i]);}
printf("%lld\n",ans);
fun();output();
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1232kb
input:
10 2 6 6 7 7 8 9 9 9 10 1 2 2 2 4 4 4 5 8 9
output:
343 0
result:
ok Accepted
Test #2:
score: 10
Accepted
time: 0ms
memory: 1304kb
input:
300 3 7 16 23 27 28 30 31 31 33 39 39 40 41 45 52 54 57 60 76 77 80 82 83 84 87 95 96 99 101 102 102...
output:
100081185 23 31 32 31 33 32 68 78 82 114 142 152 156 172 191 200 208 217 229 248 255 263 264 263
result:
ok Accepted
Test #3:
score: 10
Accepted
time: 0ms
memory: 1264kb
input:
1000 5877 11223 46751 56288 84111 90383 107139 123175 189078 189840 201516 206791 212484 235460 2355...
output:
31886434041864508 0
result:
ok Accepted
Test #4:
score: 10
Accepted
time: 0ms
memory: 1584kb
input:
300 850 586 11 803 499 983 491 676 654 701 902 727 76 292 948 875 126 701 815 10 614 170 207 109 3 3...
output:
30126307 22523 1 2 1 3 4 3 2 6 5 4 3 2 7 6 5 8 7 6 5 9 8 7 10 11 10 9 8 12 11 10 9 8 7 6 5 4 3 2 13 ...
result:
ok Accepted
Test #5:
score: 10
Accepted
time: 43ms
memory: 3240kb
input:
1000 2303 71258 47543 27966 78350 51973 54564 93554 93120 22126 73773 37093 33624 99015 98835 72871 ...
output:
33644571203 259886 2 3 2 5 4 6 5 8 9 8 7 6 5 4 3 2 10 9 8 11 10 9 8 7 6 5 4 12 11 10 9 8 7 6 5 4 14 ...
result:
ok Accepted
Test #6:
score: 10
Accepted
time: 0ms
memory: 1360kb
input:
100 96840 47122 5255 76197 81892 650 34013 82490 89220 60416 42623 1755 82567 10753 20425 70135 4333...
output:
357435899115 2347 3 2 4 3 2 5 6 7 6 5 4 3 2 8 7 6 5 4 3 9 8 7 6 5 4 3 10 9 8 7 11 10 9 8 7 6 5 4 3 1...
result:
ok Accepted
Test #7:
score: 10
Accepted
time: 33ms
memory: 3240kb
input:
800 6547222 7373197 3093209 5574969 3392784 6785440 1906423 4960424 1000638 4591726 9150475 1385022 ...
output:
26926720212052531 159242 1 2 1 3 4 3 5 6 5 4 7 6 8 7 6 5 4 9 8 7 6 5 4 3 2 1 10 9 8 7 11 10 12 11 10...
result:
ok Accepted
Test #8:
score: 10
Accepted
time: 43ms
memory: 3240kb
input:
1000 350 868 622 692 210 3582 3414 2296 2391 1002 1607 945 111 478 424 661 3009 2223 2397 2168 1618 ...
output:
5358834254 255622 4 3 5 4 3 2 1 6 5 4 3 2 1 7 6 5 4 8 7 6 5 4 3 9 10 11 10 9 8 7 6 5 4 3 12 11 10 13...
result:
ok Accepted
Test #9:
score: 10
Accepted
time: 25ms
memory: 3240kb
input:
1000 1 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 1 2 1 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1...
output:
2507 165499 1 2 3 2 5 6 7 6 5 4 8 7 6 5 4 3 9 8 7 6 5 4 10 9 8 7 6 11 10 9 8 7 12 11 10 9 8 7 6 5 4 ...
result:
ok Accepted
Test #10:
score: 10
Accepted
time: 53ms
memory: 3240kb
input:
1000 4326892 2791949 5730257 8195022 6651135 6011847 9951798 1049226 2435447 2097834 7158411 7162178...
output:
34200287502289533 258080 1 2 3 4 3 2 1 5 4 3 6 5 4 7 9 10 9 8 11 12 11 10 13 12 11 14 13 12 11 10 9 ...
result:
ok Accepted
Extra Test:
score: 0
Extra Test Passed