求助
查看原帖
求助
847562
tyy_2012楼主2023/7/23 21:49

前两个WA后面的全TLE

#include<bits/stdc++.h>
using namespace std;
long long begin_end[100010][3],thisnum=1,thatnum,num1[100010]={0},num2[100010]={0},number,herenum=1;
int determine(){
	for(int s1=1;s1<=number;s1++)
		if(num2[s1]==0)
			return 1;
	return 0;
}
void math(){
	thatnum++;
	for(int s1=1;s1<=number;s1++)
		if(num2[s1]==0&&begin_end[s1][1]<=herenum&&begin_end[s1][2]>=herenum)
			num1[s1]+=thatnum;
		else if(herenum>begin_end[s1][2])
			num2[s1]++;
	if(thatnum<thisnum)
		math();
	herenum++;
}
int main(){
	scanf("%d",&number);
	for(int s1=1;s1<=number;s1++)
		scanf("%d%d",&begin_end[s1][1],&begin_end[s1][2]);
	while(1){
		thatnum=1;
		for(int s1=1;s1<=number;s1++)
			if(num2[s1]==0&&begin_end[s1][1]<=herenum&&begin_end[s1][2]>=herenum)
				num1[s1]+=thatnum;
			else if(herenum>begin_end[s1][2])
				num2[s1]++;
		if(thatnum<thisnum)
			math();
		thisnum++;
		if(determine()==0)
			break;
		herenum++;
	}
	for(int s1=1;s1<=number;s1++)
		printf("%d\n",num1[s1]);
	return 0;
}
2023/7/23 21:49
加载中...