QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549426#9221. Missing BoundariesAINgrayCompile Error//C++173.6kb2024-09-06 15:26:342024-09-06 15:26:34

Judging History

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

  • [2024-09-06 15:26:34]
  • 评测
  • [2024-09-06 15:26:34]
  • 提交

answer

#include <bits/stdc++.h>

void Main(void);

int main(void){
	std::ios::sync_with_stdio(false),std::cin.tie(nullptr),std::cout.tie(nullptr);
	Main();
	return 0;
}

void Yes(void){std::cout<<"TAK"<<'\n'; return;}
void No(void){std::cout<<"NIE"<<'\n'; return;}

void Case(void){
	int n,len; std::cin>>n>>len;
	std::vector<std::pair<int,int>> ve(n); for(auto&[l,r]:ve) std::cin>>l>>r;

	int both_miss=0;
	std::vector<int> l_miss,r_miss;
	std::vector<std::pair<int,int>> rg;
	for(const auto[l,r]:ve) if(l==-1 and r==-1) ++both_miss; else if(l==-1) l_miss.push_back(r); else if(r==-1) r_miss.push_back(l); else rg.push_back({l,r});
	std::sort(l_miss.begin(),l_miss.end());
	std::sort(r_miss.begin(),r_miss.end());
	std::sort(rg.begin(),rg.end());

	std::set<int> set;
	for(const auto[l,r]:ve) {
		if(l!=-1){
			if(set.find(l)==set.end()) set.insert(l);
			else {No(); return;}
		} 
		if(r!=-1 and r!=l){
			if(set.find(r)==set.end()) set.insert(r);
			else {No(); return;}
		}
	}

	for(int i=1;i<int(rg.size());++i) if(rg[i].first<=rg[i-1].second) {No(); return;}

	for(const auto[l,r]:rg){
		int l_miss_lh=std::lower_bound(l_miss.begin(),l_miss.end(),l)-l_miss.begin()-1;
		int l_miss_rh=std::lower_bound(l_miss.begin(),l_miss.end(),r)-l_miss.begin();
		int r_miss_lh=std::lower_bound(r_miss.begin(),r_miss.end(),l)-r_miss.begin()-1;
		int r_miss_rh=std::lower_bound(r_miss.begin(),r_miss.end(),r)-r_miss.begin();
		if(l_miss_lh+1!=l_miss_rh) {No(); return;}
		if(r_miss_lh+1!=r_miss_rh) {No(); return;}
	}

	std::vector<std::pair<int,int>> wait();
	if(rg.empty()) wait.push_back({1,len});
	else{
		if(rg.front().first>1) wait.push_back({1,rg.front().first-1});
		for(int i=1;i<int(rg.size());++i) if(rg[i-1].second+1<=rg[i].first-1) wait.push_back({rg[i-1].second+1,rg[i].first-1});
		if(rg.back().second<len) wait.push_back({rg.back().second+1,len});
	}

	int both_chance=0,both_need=0,l_miss_p=0,r_miss_p=0;
	for(int i=0;i<int(rg.size());++i){
		auto [l,r] = rg[i];

		int last=-1;
		while((l_miss_p<int(l_miss.size()) or r_miss_p<int(r_miss.size())) and l<=r){
			if(l_miss_p<int(l_miss.size()) and r_miss_p<int(r_miss.size())){
				if(l_miss[l_miss_p]<r_miss[r_miss_p]){
					if(l<=l_miss[l_miss_p] and l_miss[l_miss_p]<=r){
						both_chance+=l_miss[l_miss_p]-l;
						l=l_miss[l_miss_p]+1;
						++l_miss_p;
						last=-1;
					}else{break;}
				}else{
					if(l<=r_miss[r_miss_p] and r_miss[r_miss_p]<=r){
						if(last==-1){
							++both_need;
							both_chance+=r_miss[r_miss_p]-l;
							l=r_miss[r_miss_p]+1;
							++r_miss_p;
							last=1;
						}else{
							both_chance+=r_miss[r_miss_p]-l;
							l=r_miss[r_miss_p]+1;
							++r_miss_p;
							last=1;
						}
					}else{break;}
				}
			}else if(l_miss_p<int(l_miss.size())){
				if(l<=l_miss[l_miss_p] and l_miss[l_miss_p]<=r){
					both_chance+=l_miss[l_miss_p]-l;
					l=l_miss[l_miss_p]+1;
					++l_miss_p;
					last=-1;
				}else{break;}
			}else if(r_miss_p<int(r_miss.size())){
				if(l<=r_miss[r_miss_p] and r_miss[r_miss_p]<=r){
					if(last==-1){
						++both_need;
						both_chance+=r_miss[r_miss_p]-l;
						l=r_miss[r_miss_p]+1;
						++r_miss_p;
						last=1;
					}else{
						both_chance+=r_miss[r_miss_p]-l;
						l=r_miss[r_miss_p]+1;
						++r_miss_p;
						last=1;
					}
				}else{break;}
			}
		}

		if(l<=r){
			++both_need;
			both_chance+=r-l;
		}
	}

	if(0<= both_miss-both_need and both_miss-both_need <=both_chance) {Yes(); return;}
	else {No(); return;}
	return;
}

void Main(void){
	int t; std::cin>>t;
	for(int i=1;i<=t;++i) Case();
	return;
}

Details

answer.code: In function ‘void Case()’:
answer.code:49:45: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
   49 |         std::vector<std::pair<int,int>> wait();
      |                                             ^~
answer.code:49:45: note: remove parentheses to default-initialize a variable
   49 |         std::vector<std::pair<int,int>> wait();
      |                                             ^~
      |                                             --
answer.code:50:29: error: request for member ‘push_back’ in ‘wait’, which is of non-class type ‘std::vector<std::pair<int, int> >()’
   50 |         if(rg.empty()) wait.push_back({1,len});
      |                             ^~~~~~~~~
answer.code:52:45: error: request for member ‘push_back’ in ‘wait’, which is of non-class type ‘std::vector<std::pair<int, int> >()’
   52 |                 if(rg.front().first>1) wait.push_back({1,rg.front().first-1});
      |                                             ^~~~~~~~~
answer.code:53:92: error: request for member ‘push_back’ in ‘wait’, which is of non-class type ‘std::vector<std::pair<int, int> >()’
   53 |                 for(int i=1;i<int(rg.size());++i) if(rg[i-1].second+1<=rg[i].first-1) wait.push_back({rg[i-1].second+1,rg[i].first-1});
      |                                                                                            ^~~~~~~~~
answer.code:54:47: error: request for member ‘push_back’ in ‘wait’, which is of non-class type ‘std::vector<std::pair<int, int> >()’
   54 |                 if(rg.back().second<len) wait.push_back({rg.back().second+1,len});
      |                                               ^~~~~~~~~