UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#203791#2850. 小明的套娃snow_trace100917ms26384kbC++111.8kb2024-03-21 10:38:432024-03-21 17:10:03

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define lowbit(x) x&(-x)
const int M = 500000;
int ans[500005],dp[500005],tree[500005];

struct node{
	int a,b,v,id;
}a[500005];;int n,q;
bool cmp(node a,node b){
	if(a.b == b.b){
		if(a.a == b.a)return a.v>b.v;
		return a.a<b.a;
	}return a.b<b.b;
}void update(int pos,int add){
	for(int i = pos;i<=M;i+=lowbit(i))tree[i] = max(tree[i],add);
}int query(int pos){
	int mx =0;for(int i =pos;i>0;i-=lowbit(i))mx = max(mx,tree[i]);return mx;
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> q;vector<int>pp;
	for(int i = 1;i<=n;i++){
		cin >> a[i].a >> a[i].b;a[i].v = 1;a[i].v = 1;a[i].id = i;
		pp.push_back(a[i].a);
	}for(int i = n+1;i<=n+q;i++){
		cin >> a[i].a >> a[i].b;a[i].v = 0;a[i].v = 0;a[i].b++;a[i].id = i;
		pp.push_back(a[i].a);
	}//for(int i = 1;i<=n;i++)cout << a[i].a << " " << a[i].b << " " << a[i].v << " " << a[i].id << endl;
	//cout << endl;
	sort(pp.begin(),pp.end());pp.erase(unique(pp.begin(),pp.end()),pp.end());
	for(int i = 1;i<=n+q;i++){
		a[i].a = pp.size()-(lower_bound(pp.begin(),pp.end(),a[i].a)-pp.begin());
	}sort(a+1,a+1+n+q,cmp);
	
	for(int i = 1;i<=n+q;){
		int j = i;
		while(j<=n+q and a[j].b == a[i].b)j++;
		for(int k = i;k<j;k++){
			dp[k] = a[k].v+query(a[k].a);ans[a[k].id] = dp[k];
		}for(int k = i;k<j;k++)update(a[k].a,dp[k]);
	//	cout << " " << i << " " << j << endl;
		i = j;
	}//for(int i = 1;i<=n+q;i++)cout << a[i].a << " " << a[i].b << " " << a[i].v << " " << a[i].id  << " " << dp[i]<< endl;
	for(int i = n+1;i<=n+q;i++)cout << ans[i] << '\n';
	
	return 0;
}/*
最小链覆盖 = 最长反链。
把询问也当作点放进去跑LIS。 
7 3
9 5
3 7
10 6
5 10
2 6
10 10
4 1
10 5
3 5
3 9

*/

详细

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

Test #1:

score: 10
Accepted
time: 1ms
memory: 1316kb

input:

50 49
811966738 378632711
986631770 389425472
375285328 507732172
994103075 304389409
446789928 4873...

output:

5
8
7
3
9
6
11
3
5
7
4
4
10
4
8
8
5
6
7
12
7
5
7
3
2
9
5
2
11
11
4
5
3
5
6
2
3
4
3
7
9
2
8
3
8
11
4
...

result:

ok 49 lines

Test #2:

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

input:

50 49
567055707 58892634
737313670 991420259
161015631 678562871
462848177 289392886
895953827 41187...

output:

3
9
11
1
2
3
8
8
0
6
8
8
1
9
5
3
6
2
7
3
7
8
3
4
5
5
0
1
3
1
4
1
3
5
7
8
5
6
8
5
9
5
1
4
8
9
5
3
10

result:

ok 49 lines

Test #3:

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

input:

50 49
930211120 235424114
525123346 770495521
470434976 481200865
390389055 83279238
249662298 28018...

output:

7
4
3
3
7
10
8
3
6
10
6
10
6
9
10
4
0
10
5
7
7
9
8
1
10
7
8
5
6
9
6
3
5
2
0
0
2
0
1
0
5
8
0
5
5
0
7
...

result:

ok 49 lines

Test #4:

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

input:

50 49
941295973 391152373
358083775 170525922
836118232 123805832
474220117 522716583
100518885 8771...

output:

7
5
4
5
5
2
5
4
6
2
1
5
9
1
7
6
6
5
7
5
7
6
0
1
2
2
6
1
8
7
8
5
7
5
7
4
5
10
4
5
4
2
7
8
6
2
11
4
4

result:

ok 49 lines

Test #5:

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

input:

50 49
61191973 564354058
512787694 852933636
641876502 275395669
428982518 796560030
397182165 57002...

output:

4
5
11
12
2
9
8
11
2
4
3
6
2
1
4
2
2
2
5
3
3
2
6
8
6
7
3
5
6
10
3
1
11
0
6
1
4
1
5
2
1
8
9
8
13
6
4
...

result:

ok 49 lines

Test #6:

score: 10
Accepted
time: 2ms
memory: 1752kb

input:

3000 2999
41979397 323635534
161588038 131873447
307913371 46256784
858454515 14084282
786988666 668...

output:

35
29
23
73
57
28
80
29
26
74
34
21
19
50
34
34
31
43
52
53
31
94
35
36
71
42
76
20
30
3
23
43
40
65...

result:

ok 2999 lines

Test #7:

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

input:

3000 2999
277515933 56610884
417512091 340657915
451278245 969080762
314665213 245045004
670013317 5...

output:

90
34
67
59
95
57
24
49
50
96
81
37
28
30
39
72
45
62
43
35
40
85
30
2
25
40
58
40
51
42
83
57
72
54...

result:

ok 2999 lines

Test #8:

score: 10
Accepted
time: 309ms
memory: 26384kb

input:

200000 199999
127483569 579735802
233136777 229310663
10252697 513352468
706869872 646909474
8212017...

output:

530
373
243
400
422
213
652
171
756
113
596
186
320
509
614
540
509
50
467
381
534
261
558
421
428
1...

result:

ok 199999 lines

Test #9:

score: 10
Accepted
time: 306ms
memory: 26384kb

input:

200000 199999
267403501 433759481
384127363 607584990
143554167 955322994
326347114 247979222
474240...

output:

509
321
504
170
483
642
222
735
80
539
327
653
323
421
772
549
487
637
740
122
562
561
123
278
57
24...

result:

ok 199999 lines

Test #10:

score: 10
Accepted
time: 295ms
memory: 26384kb

input:

200000 199999
713715470 129348179
899500867 428136001
420930115 662782322
149776097 504795520
663272...

output:

707
193
225
732
6
827
321
415
130
563
353
538
647
180
467
588
524
750
257
271
135
649
63
562
309
324...

result:

ok 199999 lines