QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#608420#5507. InvestorsQHhee004WA 5ms6032kbC++171.6kb2024-10-03 21:45:492024-10-03 21:45:51

Judging History

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

  • [2024-10-03 21:45:51]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:6032kb
  • [2024-10-03 21:45:49]
  • 提交

answer

#include<iostream>
#include<map>
#include<algorithm>
#include<set>
using namespace std;
const int inf=1e9+7,N=6005;
int tot,a[N],b[N];
#define lowbit(x) x&-x
class Tree_Array {
	private:
		int bit[N];
	public:
		void add(int x,int y) {
			while(x<=tot)bit[x]+=y,x+=lowbit(x);
		}
		int get(int x) {
			int sum=0;
			while(x)sum+=bit[x],x-=lowbit(x);
			return sum;
		}
} bit1[N],bit2[N];
void solve() {
	int n,K;
	scanf("%d%d",&n,&K);
	for(int i=1; i<=n; i++) {
		scanf("%d",&a[i]);b[i]=a[i];
	}
	map<int,int>F;
	tot=0;
	sort(b+1,b+1+n);
	for(int i=1; i<=n; i++)
		if(F[b[i]]==0)F[b[i]]=++tot;
	for(int i=1; i<=n; i++)a[i]=F[a[i]];
	int res=0;
	for(int i=1; i<=n; i++) {
		for(int j=i+1; j<=n; j++)
			if(a[j]<a[i])res++;
	}
	set<int> S;
	set<int> :: iterator itr;
	S.insert(1);
	while(K--) {
		int sum=0,mxt=0,k=0,layer=0;
		itr=S.begin();
		for(int i=1; i<=n; i++) {
			if(itr!=S.end()&&i==*itr) {
				layer++,itr++;
			}
			bit1[layer].add(a[i],1);
		}
		layer=0,itr=S.begin();
		for(int i=1; i<=n; i++) {
			if(itr!=S.end()&&i==*itr) {
				layer++,itr++;
			}
			bit1[layer].add(a[i],-1);
			sum=sum+bit1[layer].get(a[i]-1);
//			printf("sum=%d\n",sum);
			sum=sum-bit2[layer].get(tot-a[i]);
			bit2[layer].add(tot-a[i]+1,1);
			if(sum>mxt)mxt=sum,k=i+1;
//			printf(" sum=%d\n",sum);
		}
		layer=0,itr=S.begin();
		for(int i=1; i<=n; i++) {
			if(itr!=S.end()&&i==*itr) {
				layer++,itr++;
			}
			bit2[layer].add(tot-a[i]+1,-1);
		}
//		printf("k=%d\n",k);
		res-=mxt;S.insert(k);
	}
	printf("%d\n",res);
}
int main() {
	int T;scanf("%d",&T);
	while(T--) solve();
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5924kb

input:

2
6 1
4 5 6 2 2 1
6 2
4 5 6 2 2 1

output:

2
0

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 5ms
memory: 6032kb

input:

349
6 2
2 1 2 1 2 1
48 12
42 47 39 39 27 25 22 44 45 13 5 48 38 4 37 6 24 10 42 38 12 37 31 19 44 6 29 17 7 12 7 26 35 24 15 9 37 3 27 21 33 29 34 20 14 30 31 21
48 12
1 43 17 46 17 39 40 22 25 2 22 12 4 11 38 12 4 11 1 5 39 44 37 10 19 20 42 45 2 45 37 20 48 34 16 41 23 18 13 44 47 21 29 4 23 18 16...

output:

1
18
15
145
0
2
1
0
14
13
24
0
0
0
1
0
0
-9225
-4170
0
0
-5712
-2448
161
3
0
0
1
0
-3
-4097
-4624
-259
0
1
-1
3
0
0
1
0
0
1
0
-5377
1
4
-1686
0
0
0
-3454
-834
-2950
0
2
0
2
0
-4
8
280
0
0
35
4
0
1
0
-594
3
0
0
0
-4355
-3630
0
0
4
0
0
0
0
-3
-2394
0
0
0
0
0
-3822
-5681
3
0
0
-3070
2
-6226
-1548
0
-58...

result:

wrong answer 9th lines differ - expected: '13', found: '14'