QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#644556#4270. Double AttendanceSimonLJK0 1ms9768kbC++143.4kb2024-10-16 14:35:382024-10-16 14:35:39

Judging History

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

  • [2024-10-16 14:35:39]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:9768kb
  • [2024-10-16 14:35:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+99,inf=1e16;
int n,k;
struct node{
	int l,r;
	bool operator <(const node&A) const{
		return r<A.r;
	}
}p[2][N];
int cnt[2];
struct info{
	int tim,las;
	bool operator <(const info&A) const{
		return tim<A.tim||(tim==A.tim&&las<A.las);
	}
};
info f[2][N][2];
info gg[4];
void update(info *g,info a){
	gg[0]=g[0]; gg[1]=g[1]; gg[2]=a;
	sort(gg,gg+2+1);
	g[0]=gg[0];
	if(gg[1].las<g[0].las) g[1]=gg[1];
	else g[1]=gg[2];
	return;
}
int query(int tp,int x){
	if(x==0) return 0;
	int l=1,r=cnt[tp],mid,re=cnt[tp]+1;
	while(l<=r){
		mid=(l+r)/2;
		if(p[tp][mid].r>=x) re=mid,r=mid-1;
		else l=mid+1;
	}
	return re;
}
void solve(){
	int n1,n2;
	cin>>n1>>n2>>k;
	k*=10000;
	n=n1+n2;
	int l,r,tp;
	cnt[0]=cnt[1]=0;
	for(int i=1;i<=n1;i++){
		cin>>l>>r; tp=0;
		l*=10000; r*=10000; r--;
		p[tp][++cnt[tp]]=(node){l,r};
	}
	for(int i=1;i<=n2;i++){
		cin>>l>>r; tp=1;
		l*=10000; r*=10000; r--;
		p[tp][++cnt[tp]]=(node){l,r};
	}
	sort(p[0]+1,p[0]+cnt[0]+1); p[0][cnt[0]+1]=(node){inf,inf};
	sort(p[1]+1,p[1]+cnt[1]+1); p[1][cnt[1]+1]=(node){inf,inf};
	info init=(info){inf,0};
	for(int i=0;i<=n;i++)
		f[0][i][0]=f[0][i][1]=f[1][i][0]=f[1][i][1]=init;
	f[0][0][0]=(info){0,0};
	int id1,id2,id3,id4,id5,id6,id7,id8;
	for(int i=0;i<=n;i++){
		id1=query(1,f[0][i][0].tim+k);
		if(id1==f[0][i][0].las)
			update(f[1][i+(id1!=f[0][i][0].las)],(info){max(f[0][i][0].tim+k,p[1][id1].l),query(0,f[0][i][0].tim)});
		id3=query(1,f[0][i][1].tim+k);
		if(id3==f[0][i][1].las)
			update(f[1][i+(id3!=f[0][i][1].las)],(info){max(f[0][i][1].tim+k,p[1][id3].l),query(0,f[0][i][1].tim)});

		id5=query(0,f[1][i][0].tim+k);
		if(id5==f[1][i][0].las)
			update(f[0][i+(id5!=f[1][i][0].las)],(info){max(f[1][i][0].tim+k,p[0][id5].l),query(1,f[1][i][0].tim)});
		id7=query(0,f[1][i][1].tim+k);
		if(id7==f[1][i][1].las)
			update(f[0][i+(id7!=f[1][i][1].las)],(info){max(f[1][i][1].tim+k,p[0][id7].l),query(1,f[1][i][1].tim)});


		id1=query(1,f[0][i][0].tim+k);
		update(f[1][i+(id1!=f[0][i][0].las)],(info){max(f[0][i][0].tim+k,p[1][id1].l),id2=query(0,f[0][i][0].tim)});
		id3=query(1,f[0][i][1].tim+k);
		update(f[1][i+(id3!=f[0][i][1].las)],(info){max(f[0][i][1].tim+k,p[1][id3].l),id4=query(0,f[0][i][1].tim)});
		id5=query(0,f[1][i][0].tim+k);
		update(f[0][i+(id5!=f[1][i][0].las)],(info){max(f[1][i][0].tim+k,p[0][id5].l),id6=query(1,f[1][i][0].tim)});
		id7=query(0,f[1][i][1].tim+k);
		update(f[0][i+(id7!=f[1][i][1].las)],(info){max(f[1][i][1].tim+k,p[0][id7].l),id8=query(1,f[1][i][1].tim)});
		
		while(p[0][id2].l>f[0][i][0].tim) id2--;
		if(id2<cnt[0]) update(f[0][i+1],(info){p[0][id2+1].l,f[0][i][0].las});
		while(p[0][id4].l>f[0][i][1].tim) id4--;
		if(id4<cnt[0]) update(f[0][i+1],(info){p[0][id4+1].l,f[0][i][1].las});
		while(p[1][id6].l>f[1][i][0].tim) id6--;
		if(id6<cnt[1]) update(f[1][i+1],(info){p[1][id6+1].l,f[1][i][0].las});
		while(p[1][id8].l>f[1][i][1].tim) id8--;
		if(id8<cnt[1]) update(f[1][i+1],(info){p[1][id8+1].l,f[1][i][1].las});
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(f[0][i][0].tim<inf||f[0][i][1].tim<inf||f[1][i][0].tim<inf||f[1][i][1].tim<inf) ans=i;
	cout<<ans<<'\n';
	return;
}
signed main(){
//	freopen("move.in","r",stdin);
//	freopen("move.out","w",stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int T; T=1;
	while(T--) solve();
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 5
Accepted
time: 1ms
memory: 9724kb

input:

3 1 8
10 20
100 101
20 21
15 25

output:

3

result:

ok single line: '3'

Test #2:

score: 5
Accepted
time: 1ms
memory: 9768kb

input:

1 5 3
1 100
1 2
2 3
3 4
4 5
5 6

output:

4

result:

ok single line: '4'

Test #3:

score: 5
Accepted
time: 1ms
memory: 9764kb

input:

10 10 5
4 9
43 48
69 70
70 72
52 67
75 83
100 103
103 1501
10 27
28 40
5 7
27 29
30 39
40 42
42 45
67 80
0 5
45 59
10 20
22 23

output:

18

result:

ok single line: '18'

Test #4:

score: 0
Wrong Answer
time: 1ms
memory: 9708kb

input:

1 1 1
0 1
0 1

output:

2

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #104:

score: 0
Wrong Answer
time: 1ms
memory: 9744kb

input:

1 1 1
0 1
0 1

output:

2

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%