QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#644562#4270. Double AttendanceSimonLJK0 2ms9864kbC++143.4kb2024-10-16 14:37:052024-10-16 14:37:08

Judging History

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

  • [2024-10-16 14:37:08]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:9864kb
  • [2024-10-16 14:37:05]
  • 提交

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++; r++;
		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++; r++;
		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: 0ms
memory: 9784kb

input:

3 1 8
10 20
100 101
20 21
15 25

output:

3

result:

ok single line: '3'

Test #2:

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

input:

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

output:

5

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #104:

score: 6
Accepted
time: 1ms
memory: 9864kb

input:

1 1 1
0 1
0 1

output:

1

result:

ok single line: '1'

Test #105:

score: 0
Wrong Answer
time: 2ms
memory: 9864kb

input:

1 2000 2
999999996 1000000000
336 337
502 503
1906 1907
963 964
1351 1352
1795 1796
1510 1511
304 305
1930 1931
1735 1736
1469 1470
338 339
813 814
182 183
209 210
321 322
849 850
721 722
394 395
889 890
1758 1759
1440 1441
560 561
1470 1471
1916 1917
793 794
1366 1367
158 159
1602 1603
214 215
1119...

output:

2001

result:

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

Subtask #4:

score: 0
Skipped

Dependency #1:

0%