QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#468412#7523. Partially Free Mealliuzhenhao09WA 685ms203412kbC++201.6kb2024-07-08 20:39:372024-07-08 20:39:39

Judging History

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

  • [2024-07-08 20:39:39]
  • 评测
  • 测评结果:WA
  • 用时:685ms
  • 内存:203412kb
  • [2024-07-08 20:39:37]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int SZ = 1e9;
const int INF = 1e16 + 7;
struct node{
	int a,b;
	bool operator <(const node& kkk)const{
		return b < kkk.b;
	}
}x[200010];
int n,tot = 0;
int rt[200010],sz[10000010],val[10000010],ls[10000010],rs[10000010],ans[200010];
void pushup(int i){
	sz[i] = sz[ls[i]] + sz[rs[i]];
	val[i] = val[ls[i]] + val[rs[i]];
}
int New(int i){
	tot++;
	sz[tot] = sz[i],val[tot] = val[i],ls[tot] = ls[i],rs[tot] = rs[i];
	return tot;
}
void upd(int& i,int l,int r,int pos,int v1,int v2){
	i = New(i);
	sz[i] += v1;
	val[i] += v2;
	if(l == r) return;
	int mid = (l + r) >> 1;
	if(pos <= mid) upd(ls[i],l,mid,pos,v1,v2);
	else upd(rs[i],mid + 1,r,pos,v1,v2);
	pushup(i);
}
int query(int i,int l,int r,int rk){
	if(!i || !rk) return 0;
	if(l == r) return l;
	int mid = (l + r) >> 1;
	if(rk <= sz[ls[i]]) return query(ls[i],l,mid,rk);
	else return val[ls[i]] + query(rs[i],mid + 1,r,rk - sz[ls[i]]);
}
void solve(int l,int r,int ql,int qr){
	if(l > r) return;
	int mid = (l + r) >> 1;
	int tl = max(ql,mid),tr = qr;
	int mn = INF,id = -1;
	for(int i = tl; i <= tr; i++){
		int tmp = x[i].b + x[i].a + query(rt[i - 1],1,SZ,mid - 1);
		if(mn > tmp) mn = tmp,id = i;
	}
	ans[mid] = mn;
	if(l == r) return;
	solve(l,mid - 1,ql,id);
	solve(mid + 1,r,id,qr); 
}
signed main(){
	scanf("%lld",&n);
	for(int i = 1; i <= n; i++) scanf("%lld %lld",&x[i].a,&x[i].b);
	sort(x + 1,x + n + 1);
	for(int i = 1; i <= n; i++) rt[i] = rt[i - 1],upd(rt[i],1,SZ,x[i].a,1,x[i].a);
	solve(1,n,1,n);	
	for(int i = 1; i <= n; i++) printf("%lld\n",ans[i]);
	return 0;
}

详细

Test #1:

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

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 685ms
memory: 203412kb

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:

1318594
3208018
5570526
7340845
9223347
11149865
12332210
13476823
14788280
16172895
17768627
19336633
20693779
22005236
23389851
25073157
26760338
28509336
30294967
32093959
33976461
35893858
37754030
39588384
41470886
43388283
45309771
47309654
48837539
50417767
52079411
53762717
55190044
56577630...

result:

wrong answer 25828th lines differ - expected: '894947484423', found: '894878200462'