QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#764735#7523. Partially Free Mealucup-team4352#WA 177ms50256kbC++232.0kb2024-11-20 10:29:192024-11-20 10:29:29

Judging History

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

  • [2024-11-20 10:29:29]
  • 评测
  • 测评结果:WA
  • 用时:177ms
  • 内存:50256kb
  • [2024-11-20 10:29:19]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int n,pos[maxn],loc[maxn];
struct Data{
	int x,y;
}a[maxn];
int b[maxn],c[maxn];
bool comp(Data A,Data B) {
	if(A.y==B.y) return A.x>B.x;
	return A.y<B.y;
}
int cnt,sum[maxn*60],L[maxn*60],R[maxn*60];
void update(int rt,int l,int r,int x) {
	sum[rt]++;
	if(l==r) return;
	int mid=l+r>>1;
	if(x<=mid) {
		if(!L[rt]) L[rt]=++cnt;
		update(L[rt],l,mid,x);
	}
	else {
		if(!R[rt]) R[rt]=++cnt;
		update(R[rt],mid+1,r,x);
	}
}
int query(int rt,int l,int r,int x) {
	if(x>=r) return sum[rt];
	int mid=l+r>>1;
	if(x<=mid) {
		int res=0;
		if(L[rt]) res=query(L[rt],l,mid,x);
		return res;
	}
	else {
		int res=0;
		if(L[rt]) res+=sum[L[rt]];
		if(R[rt]) res+=query(R[rt],mid+1,r,x);
		return res;
	}
}
ll res;
struct Node{
	int js[maxn<<2];
	ll sum[maxn<<2];
	void update(int rt,int l,int r,int p) {
		js[rt]++;
		sum[rt]+=b[p];
		if(l==r) return;
		int mid=l+r>>1;
		if(p<=mid) update(rt<<1,l,mid,p);
		else update(rt<<1|1,mid+1,r,p);
	}
	void query(int rt,int l,int r,int p) {
		if(!p) return;
		if(l==r) {
			res+=(ll)p*b[l];
			return;
		}
		int mid=l+r>>1;
		if(js[rt<<1]<=p) {
			res+=sum[rt<<1];
			query(rt<<1|1,mid+1,r,p-js[rt<<1]);
		}
		else query(rt<<1,l,mid,p);
	}
}T;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i) cin>>a[i].x>>a[i].y,b[i]=a[i].x;
	sort(a+1,a+1+n,comp);
	sort(b+1,b+1+n);
	int m=unique(b+1,b+1+n)-b-1;
	for(int i=1;i<=n;++i) c[i]=lower_bound(b+1,b+1+m,a[i].x)-b;
	pos[1]=1;
	update(0,0,2e9,a[1].x);
	loc[1]=1;
	for(int i=2;i<=n;++i) {
		pos[i]=query(0,0,2e9,a[i].x+a[i].y-a[i-1].y)+1;
		loc[pos[i]]=i;
		update(0,0,2e9,a[i].x);
	}
	int now=1; 
	for(int i=1;i<=n;i++){
		loc[i]=max(loc[i],loc[i-1]);
		//k=i的答案为,maxb取b[loc[i]]时的前k大的sum 
		while(now<loc[i]) {
			T.update(1,1,m,c[now]);
			now++;
		}
		res=(ll)a[loc[i]].x+a[loc[i]].y;
		T.query(1,1,m,i-1);
		cout<<res<<'\n';
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 11868kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 177ms
memory: 50256kb

input:

200000
466436993 804989151
660995237 756645598
432103296 703610564
6889895 53276988
873617076 822481192
532911431 126844295
623111499 456772252
937464699 762157133
708503076 786039753
78556972 5436013
582960979 398984169
786333369 325119902
930705057 615928139
924915828 506145001
164984329 208212435...

output:

102043294
224635328
224644015
675770530
675782549
675795075
675812301
675831882
862773973
862797373
862824627
862856425
862888707
862929706
974809359
974852723
974896322
974943405
974992243
975043130
975096523
975151532
975213060
975275656
975344030
975413790
975484372
975557816
975631334
975705789
...

result:

wrong answer 1st lines differ - expected: '1318594', found: '102043294'