C++,codeforce 2053B

//codeforce 2053B
#include <iostream>
#include <vector>
#include <unordered_set>
#include <map>
#include <algorithm>
void solve(){
    int n;std::cin>>n;
    std::vector<int> left(n),right(n);
    std::vector<int> spaces(n);
    std::vector<int> mark;
    std::map<int,int> markCount;
    for(int i = 0;i<n;++i){
        std::cin>>left[i];std::cin>>right[i];
        spaces[i] = right[i]-left[i]+1;
        if(left[i]==right[i]){
            mark.push_back(left[i]);
            markCount[left[i]]++;
        }
    }
    std::sort(mark.begin(),mark.end());
    mark.erase(std::unique(mark.begin(),mark.end()),mark.end());
    for(int i = 0;i<n;++i){
        int count = std::upper_bound(mark.begin(),mark.end(),right[i])-std::lower_bound(mark.begin(),mark.end(),left[i]);
        spaces[i]-=count;
    }
    for(int i = 0;i<n;++i){
        bool flag = false;
        if(left[i]==right[i]){
            if(markCount[left[i]]==1){
                flag = true;
            }
        }else{
            if(spaces[i]>0){
                flag = true;
            }
        }
        if(flag){
            std::cout<<1;
        }else{
            std::cout<<0;
        }
    }
    std::cout<<std::endl;
}
int main(){
    int t;
    std::cin>>t;
    while(t--){
        solve();
    }
}
posted @ 2025-03-07 20:25  Kazuma_124  阅读(10)  评论(0)    收藏  举报