求助,离散化60pts,WA at #1,2,3,4
查看原帖
求助,离散化60pts,WA at #1,2,3,4
636358
WindyDay楼主2024/7/31 12:48
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
vector<int> post;
set<int> st;
int wall[2005]; 
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) {
        int ta,tb;
        scanf("%d%d",&ta,&tb);
        ta=max(ta,1);
        tb=min(tb,n);
        post.push_back(ta);
        post.push_back(tb);
    }
    vector<int> tmp(post);
    sort(tmp.begin(),tmp.end());
    tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
    for(int i=0;i<2*m;i++) {
        post[i]=lower_bound(tmp.begin(),tmp.end(),post[i])-tmp.begin();
    }
    for(int i=1;i<=m;i++) {
        int l=2*i-2,r=2*i-1;
        for(int j=post[l];j<=post[r];j++) {
            wall[j]=i;
        }
    }
    bool flag=0;
    for(int i=0;i<2*m;i++) {
        st.insert(wall[i]);
        if(!wall[i]) flag=1;
    }
    printf("%d\n",st.size()-flag);
    return 0;
}
2024/7/31 12:48
加载中...