QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#863793 | #5946. Up and Down | Bkos | 0 | 7ms | 3840kb | C++14 | 1.5kb | 2025-01-19 22:31:49 | 2025-01-19 22:31:49 |
answer
#include <bits/stdc++.h>
#define mkp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template <typename T>
inline void in (T &x) {
char c; int f=1;
do {c=getchar (); f=c=='-'?-1:f;} while (c>'9' || c<'0');
for (x=0;c>='0' && c<='9';c=getchar ()) x=(x<<1)+(x<<3)+(c^48);
x*=f;
}
template <typename T>
inline void out (T x,char c) {
if (x==0) {putchar ('0'),putchar (c); return ;}
if (x<0) putchar ('-'),x=-x;
int sta[25],k=0;
while (x) sta[++k]=x%10,x/=10;
while (k) putchar (sta[k--]+'0');
putchar (c);
}
const int N=1e3+100;
int n,m;
int a[N],d[N];
int t[N];
inline void update (int x,int k) {for (int i=x;i<=m;i+=(i&-i)) t[i]+=k;}
inline int query (int x) {int res=0; for (int i=x;i;i-=(i&-i)) res+=t[i]; return res;}
inline void solve (int f[]) {
memset (f,0,sizeof (f));
memset (t,0,sizeof (t));
int sum=0;
for (int i=1;i<=n;++i) {
sum+=query (m)-query (a[i]);
f[i]=sum;
update (a[i],1);
}
}
int f1[N],f2[N];
inline void work () {
in (n);
for (int i=1;i<=n;++i) in (a[i]),d[i]=a[i];
sort (d+1,d+n+1); m=unique (d+1,d+n+1)-d-1;
for (int i=1;i<=n;++i) a[i]=lower_bound (d+1,d+m+1,a[i])-d;
solve (f1);
for (int i=1;i<=n/2;++i) swap (a[i],a[n+1-i]);
solve (f2);
int ans=0;
for (int i=0;i<=n;++i) ans+=min (f1[i],f2[n+1-i]);
out (ans,'\n');
}
int main () {
int test; in (test); for (int i=1;i<=test;++i) {
printf ("Case #%d: ",i);
work ();
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3840kb
input:
100 8 5442 347 1402 5373 9469 2281 4003 219 9 4957 3355 337 693 1627 1372 2093 4151 9135 7 127 194 735 647 584 399 288 10 531 510 496 247 70 99 398 502 515 549 10 841 629 412 310 83 145 334 611 750 947 10 244 7064 6465 7404 5190 9149 6902 211 1861 7634 10 3341 8102 4954 5745 8455 379 2986 6904 494 8...
output:
Case #1: 7 Case #2: 26 Case #3: 0 Case #4: 40 Case #5: 40 Case #6: 18 Case #7: 19 Case #8: 0 Case #9: 5 Case #10: 6 Case #11: 18 Case #12: 5 Case #13: 26 Case #14: 20 Case #15: 18 Case #16: 40 Case #17: 12 Case #18: 0 Case #19: 19 Case #20: 2 Case #21: 20 Case #22: 17 Case #23: 26 Case #24: 40 Case ...
result:
wrong answer 1st lines differ - expected: 'Case #1: 4', found: 'Case #1: 7'
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 7ms
memory: 3712kb
input:
100 615 148938 436018 160290 275822 869105 524968 565096 173649 623300 601127 564266 402562 534135 756541 87045 587390 497223 525981 14418 854242 376133 6737 747544 749040 939763 661848 541580 584761 578805 691578 421947 756284 597479 485235 874891 872708 188420 952787 244407 808782 156986 343427 16...
output:
Case #1: 4821139 Case #2: 0 Case #3: 0 Case #4: 5346237 Case #5: 4086326 Case #6: 11440 Case #7: 20587063 Case #8: 14495923 Case #9: 1925946 Case #10: 9323297 Case #11: 23780467 Case #12: 30657 Case #13: 0 Case #14: 1620767 Case #15: 204 Case #16: 1360 Case #17: 8249115 Case #18: 9989401 Case #19: 4...
result:
wrong answer 1st lines differ - expected: 'Case #1: 47639', found: 'Case #1: 4821139'