QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#863721 | #5946. Up and Down | Bkos | 0 | 5ms | 3840kb | C++14 | 1.5kb | 2025-01-19 21:37:42 | 2025-01-19 21:37:42 |
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;}
int mn[N];
inline void solve (int 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=1e9;
for (int i=1;i<=n;++i) ans=min (ans,f1[i]+f2[n-i]);
out (ans,'\n');
}
int main () {
int test; in (test); for (int i=1;i<=test;++i) {
printf ("Case #%d: ",i);
work ();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3712kb
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: 4 Case #2: 13 Case #3: 0 Case #4: 20 Case #5: 20 Case #6: 8 Case #7: 10 Case #8: 0 Case #9: 3 Case #10: 3 Case #11: 11 Case #12: 3 Case #13: 13 Case #14: 12 Case #15: 7 Case #16: 20 Case #17: 6 Case #18: 0 Case #19: 9 Case #20: 2 Case #21: 12 Case #22: 8 Case #23: 13 Case #24: 20 Case #25: ...
result:
wrong answer 11th lines differ - expected: 'Case #11: 10', found: 'Case #11: 11'
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 5ms
memory: 3840kb
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: 47650 Case #2: 0 Case #3: 0 Case #4: 51025 Case #5: 41610 Case #6: 1024 Case #7: 122691 Case #8: 96024 Case #9: 25632 Case #10: 73196 Case #11: 139241 Case #12: 1695 Case #13: 0 Case #14: 22594 Case #15: 64 Case #16: 240 Case #17: 70719 Case #18: 75568 Case #19: 44088 Case #20: 23248 Case #...
result:
wrong answer 1st lines differ - expected: 'Case #1: 47639', found: 'Case #1: 47650'