UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#169763#757. aInvisible_H20400ms4036kbC++1.6kb2023-03-09 16:52:312023-03-09 16:52:32

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k;
struct node{
	int l,r;
}a[200005];
bool cmp(node x,node y){
	if(x.r!=y.r) return x.r<y.r;
	return x.l<y.l;
}
struct Tree{
	int maxx,tag;
}xd[1000005];
inline int ls(int x){return x<<1;}
inline int rs(int x){return x<<1|1;}
inline void push_up(int x){
	xd[x].maxx=max(xd[ls(x)].maxx,xd[rs(x)].maxx);
}
inline void push_down(int id,int l,int r){
	int mid=(l+r)>>1;
	if(xd[id].tag!=0){
		xd[ls(id)].tag+=xd[id].tag; xd[rs(id)].tag+=xd[id].tag;
		xd[ls(id)].maxx+=xd[id].tag; xd[rs(id)].tag+=xd[id].tag;
		xd[id].tag=0;
	}
}
void build(int id,int l,int r){
	if(l==r){
		xd[id].maxx=xd[id].tag=0;
		return;
	}
	int mid=(l+r)>>1;
	build(ls(id),l,mid);
	build(rs(id),mid+1,r);
	push_up(id);
}
void update(int id,int l,int r,int x,int y,int t){
	if(l>=x&&r<=y){
		xd[id].tag+=t;
		xd[id].maxx+=t;
		return;
	}
	int mid=(l+r)>>1;
	push_down(id,l,r);
	if(x<=mid) update(ls(id),l,mid,x,y,t);
	if(y>mid) update(rs(id),mid+1,r,x,y,t);
	push_up(id);
}
int query(int id,int l,int r,int x,int y){
	if(l>=x&&r<=y){
		return xd[id].maxx;
	}
	int mid=(l+r)>>1,res=0; push_down(id,l,r);
	if(x<=mid) res=max(res,query(ls(id),l,mid,x,y));
	if(y>mid) res=max(res,query(rs(id),mid+1,r,x,y));
	return res;
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++){
		scanf("%d%d",&a[i].l,&a[i].r);
	}
	sort(&a[1],&a[n+1],cmp);
	int ans=0;
	for (int i=1;i<=n;i++){
		if(query(1,1,n,a[i].l,a[i].r)>=k) continue;
		update(1,1,n,a[i].l,a[i].r,1);
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}

详细

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

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1208kb

input:

17 3
1 11
5 10
5 5
14 17
11 17
4 4
5 13
1 15
1 11
1 17
12 13
10 14
8 11
2 14
10 11
2 6
12 12

output:

10

result:

wrong answer 1st numbers differ - expected: '11', found: '10'

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 1212kb

input:

17 1
3 8
7 9
15 17
7 9
4 16
8 13
1 13
14 16
5 17
2 3
9 17
8 17
4 10
6 11
6 11
15 16
13 16

output:

3

result:

wrong answer 1st numbers differ - expected: '4', found: '3'

Test #3:

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

input:

17 2
5 5
5 12
8 12
1 8
5 15
3 5
13 14
13 14
7 16
3 15
12 14
2 7
5 12
2 17
1 12
13 15
3 14

output:

7

result:

ok 1 number(s): "7"

Test #4:

score: 10
Accepted
time: 58ms
memory: 4020kb

input:

100000 1
53181 99732
73868 78625
13671 74194
20244 38430
4244 37174
47521 70192
38596 90797
24901 71...

output:

356

result:

ok 1 number(s): "356"

Test #5:

score: 0
Wrong Answer
time: 61ms
memory: 4012kb

input:

100000 1
69988 74981
23941 38636
22601 85466
5661 47788
31450 58306
8357 11961
91642 97991
63757 797...

output:

365

result:

wrong answer 1st numbers differ - expected: '361', found: '365'

Test #6:

score: 0
Wrong Answer
time: 54ms
memory: 4020kb

input:

100000 1
66583 86795
82294 90367
47884 96738
72892 91685
9373 12368
62875 76401
41033 92487
86260 87...

output:

365

result:

wrong answer 1st numbers differ - expected: '363', found: '365'

Test #7:

score: 0
Wrong Answer
time: 59ms
memory: 4036kb

input:

100000 602
41832 56793
25952 56814
8010 19229
3649 40123
57194 66430
1040 93332
84075 95680
25116 60...

output:

2809

result:

wrong answer 1st numbers differ - expected: '14813', found: '2809'

Test #8:

score: 0
Wrong Answer
time: 58ms
memory: 4032kb

input:

100000 409
17081 23219
82097 85963
35635 46773
91001 97925
20492 21634
55558 94177
3667 27117
47619 ...

output:

2452

result:

wrong answer 1st numbers differ - expected: '12153', found: '2452'

Test #9:

score: 0
Wrong Answer
time: 55ms
memory: 4032kb

input:

100000 216
73292 92330
29621 91027
46907 74317
58232 75848
74554 86074
10076 95022
11654 70159
57758...

output:

2146

result:

wrong answer 1st numbers differ - expected: '8903', found: '2146'

Test #10:

score: 0
Wrong Answer
time: 54ms
memory: 4036kb

input:

100000 23
39718 67579
16310 89632
1861 58179
25463 70124
28616 66867
48241 79514
13201 19641
8978 40...

output:

1271

result:

wrong answer 1st numbers differ - expected: '2741', found: '1271'