第一个WA了,求哪里出了问题!

P1047 [NOIP2005 普及组] 校门外的树

lixiao233 @ 2022-10-14 19:19:39

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair<int,int> PI;
int l,m,u,v;
vector <PI> seg;
int main()
{
    cin >> l >> m;
    int st = 0,ed = 0,res = 0;
    while(m--)
    {
        cin >> u >> v;
        seg.push_back({u,v});
    }
    sort(seg.begin(),seg.end());
    for(auto item : seg)
    {
        if(ed < item.first) {
            if (st != 0) res += ed - st + 1;
            st = item.first, ed = item.second;
        }
        else ed = max(ed,item.second);
    }
    if(st != 0) res += ed -st + 1;
    cout << l  + 1 - res << endl;
    return 0;
}

|