QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#863756#5946. Up and DownBkos0 6ms3840kbC++141.5kb2025-01-19 22:00:132025-01-19 22:00:22

Judging History

你现在查看的是最新测评结果

  • [2025-01-19 22:00:22]
  • 评测
  • 测评结果:0
  • 用时:6ms
  • 内存:3840kb
  • [2025-01-19 22:00:13]
  • 提交

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=1e9;
	for (int i=0;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;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
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: 1
Case #2: 0
Case #3: 0
Case #4: 0
Case #5: 0
Case #6: 1
Case #7: 0
Case #8: 0
Case #9: 0
Case #10: 0
Case #11: 0
Case #12: 0
Case #13: 1
Case #14: 0
Case #15: 0
Case #16: 0
Case #17: 0
Case #18: 0
Case #19: 1
Case #20: 0
Case #21: 0
Case #22: 0
Case #23: 0
Case #24: 0
Case #25: 0
Case #26:...

result:

wrong answer 1st lines differ - expected: 'Case #1: 4', found: 'Case #1: 1'

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 6ms
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: 3
Case #2: 0
Case #3: 0
Case #4: 3
Case #5: 1
Case #6: 0
Case #7: 15
Case #8: 9
Case #9: 1
Case #10: 1
Case #11: 6
Case #12: 3
Case #13: 0
Case #14: 9
Case #15: 0
Case #16: 0
Case #17: 0
Case #18: 5
Case #19: 10
Case #20: 2
Case #21: 17
Case #22: 15
Case #23: 3
Case #24: 5
Case #25: 7
Case ...

result:

wrong answer 1st lines differ - expected: 'Case #1: 47639', found: 'Case #1: 3'