QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#283215#7622. Yet Another CoffeeEvierWA 1ms7644kbC++141.6kb2023-12-14 08:31:502023-12-14 08:31:50

Judging History

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

  • [2023-12-14 08:31:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7644kb
  • [2023-12-14 08:31:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read(){
	int x=0;bool f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=0;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
    if(f)return x;return ~(x-1);
}
int T,n,m,cnt,tot,a[200005],lsh[200005],rt[200005];
ll c[200005],ans[200005];
struct{
	int l,r,cnt;ll v;
}t[4000005];
void ins(int &p,int q,int l,int r,int d){
	if(!p)p=++tot;
	t[p]=t[q];
	t[p].cnt++,t[p].v+=lsh[d];
	if(l==r)return;
	int mid=l+r>>1;
	if(d<=mid)ins(t[p].l,t[q].l,l,mid,d);
	else ins(t[p].r,t[q].r,mid+1,r,d);
}
ll ask(int p,int q,int l,int r,int k){
	if(l==r)return 1ll*min(t[p].cnt-t[q].cnt,k)*lsh[l];
	int mid=l+r>>1;
	if(k<=t[t[p].l].cnt-t[t[q].l].cnt)return ask(t[p].l,t[q].l,l,mid,k);
	return t[t[p].l].v-t[t[q].l].v+ask(t[p].r,t[q].r,mid+1,r,k-t[t[p].l].cnt+t[t[q].l].cnt);
}
void solve(int l,int r,int L,int R){
	if(l>r)return;
	int mid=l+r>>1,p=0;ans[mid]=1e18;
	for(int i=L;i<=R;i++)if(n-i+1>=mid){
		ll tmp=c[i]+ask(rt[n],rt[i-1],1,cnt,mid);
		if(ans[mid]>tmp)ans[mid]=tmp,p=i;
	}
	solve(l,mid-1,p,R),solve(mid+1,r,L,p);
}
int main(){
	T=read();
	while(T--){
		tot=cnt=0;
		n=read(),m=read();
		for(int i=1;i<=n;i++)a[i]=read(),c[i]=rt[i]=0,lsh[++cnt]=a[i];
		while(m--){
			int x=read(),y=read();
			c[1]-=y,c[x+1]+=y;
		}
		for(int i=1;i<=n;i++)c[i]+=c[i-1];
		sort(lsh+1,lsh+cnt+1);
		cnt=unique(lsh+1,lsh+cnt+1)-lsh-1;
		for(int i=1;i<=n;i++){
			a[i]=lower_bound(lsh+1,lsh+cnt+1,a[i])-lsh;
			ins(rt[i],rt[i-1],1,cnt,a[i]);
		}
		solve(1,n,1,n);
		for(int i=1;i<=n;i++)cout<<ans[i]<<" ";puts("");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 7644kb

input:

5
10 14
17 37 59 65 53 73 68 177 160 111
10 177
5 193
2 30
3 63
2 339
3 263
5 178
2 190
9 23
10 328
10 200
9 8
3 391
6 230
12 9
152 306 86 88 324 59 18 14 42 260 304 55
3 50
2 170
1 252
7 811
1 713
7 215
10 201
4 926
8 319
19 20
182 74 180 201 326 243 195 31 170 263 284 233 48 166 272 281 179 116 31...

output:

-2596 -2559 -2506 -2447 -2382 -2314 -2241 -2130 -1970 -1793 
-3643 -3625 -3583 -3528 -3469 -3383 -3295 -3143 -2883 -2579 -2273 -1949 
-5984 -5984 -5984 -5984 -5984 -5984 -5984 -5984 -5984 -5984 -5984 -5984 -5984 -5984 -5984 -3998 -3998 -3998 -2946 
-3474 -3474 -3474 -3474 -3474 -3474 -3474 -3474 -72...

result:

wrong answer 11th numbers differ - expected: '-3505', found: '-3643'