UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#192833#2441. 物品snow_trace1001563ms54724kbC++113.3kb2023-10-12 11:08:592023-10-12 12:01:57

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 10000;
int read(){
	int  x= 0;char c = getchar();
	while(c<'0' or c>'9')c=getchar();
	while('0'<=c and c<='9')x = x*10+(c^48),c = getchar();
	return x;
}struct node{
	int l,r;int sum1 = 0,sum2 =0 ;
	void add(int num){
		sum1+=num;sum2+=l*num;
	}
}tree1[200005],tree2[200005];
int tong[200005];
int n,c;
int a[500005],w[500005];
void push_up1(int k){
	tree1[k].sum1 = tree1[k<<1].sum1+tree1[k<<1|1].sum1;
	tree1[k].sum2 = tree1[k<<1].sum2+tree1[k<<1|1].sum2;
}void build1(int l,int r,int k){
	tree1[k].l = l,tree1[k].r = r;
	if(l+1 == r){
		tree1[k].add(tong[l]);return;
	}build1(l,l+r>>1,k<<1),build1(l+r>>1,r,k<<1|1);
	push_up1(k);return;
}void upd1(int pos,int add,int k){
	int l = tree1[k].l,r = tree1[k].r;
	if(l>pos or pos>=r)return ;
	if(l+1 == r and l == pos){
		tree1[k].add(add);return;
	}upd1(pos,add,k<<1),upd1(pos,add,k<<1|1);push_up1(k);
}int query1(int k,int x){
	if(x == 0)return 0;
	if(tree1[k].l+1 == tree1[k].r){
		return tree1[k].l*x;
	}int s1 = tree1[k<<1].sum1;
	if(x<=s1)return query1(k<<1,x);
	else return query1(k<<1|1,x-s1)+tree1[k<<1].sum2;
}void push_up2(int k){
	tree2[k].sum1 = tree2[k<<1].sum1+tree2[k<<1|1].sum1;
	tree2[k].sum2 = tree2[k<<1].sum2+tree2[k<<1|1].sum2;
}void build2(int l,int r,int k){
	tree2[k].l = l,tree2[k].r = r;
	if(l+1 == r){
		return;
	}build2(l,l+r>>1,k<<1),build2(l+r>>1,r,k<<1|1);
	push_up2(k);return;
}void upd2(int pos,int add,int k){
	int l = tree2[k].l,r = tree2[k].r;
	if(l>pos or pos>=r)return ;
	if(l+1 == r and l == pos){
		tree2[k].add(add);return;
	}upd2(pos,add,k<<1),upd2(pos,add,k<<1|1);push_up2(k);
}int query2(int k,int x){
	//cout << tree2[k].l << " " << x << " " << k << endl;
	if(x == 0)return 0;
	if(tree2[k].l+1 == tree2[k].r){
	//	cout << " "  << endl<< tree2[k].l << "   " << x << endl;
		return tree2[k].l*x;
	}int s1 = tree2[k<<1].sum1;//cout << s1  << "  " << x<< endl;
	if(x<=s1)return query2(k<<1,x);
	else return query2(k<<1|1,x-s1)+tree2[k<<1].sum2;
}vector<int>p[500005];
signed main(){
	n = read(),c = read();
	for(int i = 1;i<=n;i++)a[i] = read(),w[i] = read();
	for(int i = 1;i<=n;i++)tong[w[i]]++;
	build1(1,N+1,1),build2(1,N+1,1);
	for(int i = 1;i<=n;i++)p[a[i]].push_back(w[i]);
//	cout << query1(1,2) << endl;
	int sz =0,tot =0,mx =0 ,mxpos =0 ;
	for(int i = 1;i<=n;i++){
		for(int j =0;j<p[i-1].size();j++){tot++;
			upd1(p[i-1][j],-1,1),upd2(p[i-1][j],1,1);
		}while(sz<tot and ((i-sz>n-tot) or (query1(1,i-sz)+query2(1,sz)>c)))sz++;
	//	cout << i << " " << sz  <<" " << tot << " " << query2(1,sz) <<" " << query1(1,i-sz)<< endl;
		if(i-sz>mx)mx = i-sz,mxpos = i;
		if(sz == tot and (((i-sz>n-tot) or (query1(1,i-sz)+query2(1,sz)>c))))break;
	}vector<pair<int,int> >p1,p2;
	for(int i = 1;i<=n;i++){
		if(a[i]<mxpos)p1.push_back({w[i],i});
		else p2.push_back({w[i],i});
	}vector<int>ans;
	sort(p1.begin(),p1.end());sort(p2.begin(),p2.end());
//	for(int i =0;i<p2.size();i++)cout << p2[i].first << " " << p2[i].second << endl;cout << endl;
	cout << mx << endl << mxpos << endl;
	for(int i=0;i<mx;i++)ans.push_back(p2[i].second);
	for(int i=0;i<mxpos-mx;i++)ans.push_back(p1[i].second);
	sort(ans.begin(),ans.end());
	for(int i =0;i<ans.size();i++)printf("%lld ",ans[i]);cout << endl;
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 25476kb

input:

18 1024
8 3
8 1
16 9
17 6
2 5
12 3
1 7
7 9
17 1
14 3
2 7
17 5
2 3
2 5
2 10
8 3
2 3
17 5

output:

8
8
1 2 6 9 10 12 16 18 

result:

points 1.0 Correct

Test #2:

score: 10
Accepted
time: 4ms
memory: 25536kb

input:

20 79841
15 4337
9 6289
7 9927
12 1468
7 9390
12 9228
7 5646
8 3438
3 1614
3 7048
10 8840
15 2349
16...

output:

10
10
1 4 6 11 12 13 14 17 19 20 

result:

points 1.0 Correct

Test #3:

score: 10
Accepted
time: 4ms
memory: 25604kb

input:

1888 987654
1082 243
1341 309
1524 959
324 593
894 952
1428 587
1367 91
1669 683
616 866
958 791
172...

output:

949
949
1 2 3 6 7 8 10 11 12 13 14 16 22 23 25 27 28 29 30 34 35 36 39 40 41 42 44 47 48 49 50 51 55...

result:

points 1.0 Correct

Test #4:

score: 10
Accepted
time: 4ms
memory: 25676kb

input:

1999 12000000
1112 2799
524 6890
686 6713
1803 4478
940 4341
1391 8972
953 592
454 7711
524 8224
127...

output:

978
978
1 4 6 11 12 14 15 18 19 20 21 24 25 28 30 33 34 37 38 41 45 46 48 50 52 53 56 58 59 66 68 70...

result:

points 1.0 Correct

Test #5:

score: 10
Accepted
time: 8ms
memory: 25680kb

input:

2000 9788123
296 3976
154 3441
78 9146
1443 6444
1799 2843
1482 6843
1526 3159
1956 9324
1442 1001
5...

output:

997
997
4 5 6 7 8 9 11 18 20 26 28 29 30 31 32 34 36 38 41 42 44 45 48 51 53 54 55 56 57 60 61 63 65...

result:

points 1.0 Correct

Test #6:

score: 10
Accepted
time: 160ms
memory: 36784kb

input:

200000 87654321
33240 503
90721 868
64272 858
170928 616
92246 213
50575 59
148252 954
87639 739
328...

output:

100168
100168
4 7 12 16 17 18 20 21 26 27 28 29 30 32 34 37 38 43 44 47 48 51 54 55 57 60 62 63 66 6...

result:

points 1.0 Correct

Test #7:

score: 10
Accepted
time: 178ms
memory: 36860kb

input:

200000 987654321
199051 7573
6332 5631
35615 9816
185684 9227
198894 8029
185684 2173
54203 2887
107...

output:

98978
98978
1 4 5 6 8 11 12 13 16 17 18 19 20 22 27 28 31 32 33 34 35 37 40 46 51 53 54 57 60 61 62 ...

result:

points 1.0 Correct

Test #8:

score: 10
Accepted
time: 383ms
memory: 50296kb

input:

444444 998244353
243276 2272
436596 1761
70822 1547
263965 942
280972 2658
87160 421
268504 2945
103...

output:

222615
222615
1 2 4 5 7 10 12 17 19 20 23 24 25 26 29 30 33 34 36 37 40 42 44 45 48 50 56 59 60 61 6...

result:

points 1.0 Correct

Test #9:

score: 10
Accepted
time: 372ms
memory: 52532kb

input:

500000 999999999
131412 807
486292 804
462352 1139
52896 196
426775 1655
18059 2099
224414 1308
2851...

output:

254580
254580
2 3 5 8 9 10 13 14 15 17 18 20 24 26 27 28 29 34 35 37 41 42 44 45 48 56 57 58 59 61 6...

result:

points 1.0 Correct

Test #10:

score: 10
Accepted
time: 450ms
memory: 54724kb

input:

500000 1000000000
42362 5090
327916 7618
221602 679
295161 1419
69703 4221
108614 6788
210597 6940
2...

output:

231450
231450
2 4 12 14 16 18 19 24 27 33 37 42 43 47 49 52 53 55 56 59 60 62 67 68 69 74 75 77 78 7...

result:

points 1.0 Correct