为什么只能ac2个点?
原题链接:65.校门外的树2025-07-06 10:02:18
发布于:广东
不知道自己给的样例都能过
不知道为什么
为什么
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>
#define ll long long
#define si short int
#define pi 3.1415926
using namespace std;
const int N=3e5+9;
const ll INF=0xffffff;
struct node{
ll l,r;
bool allDel;
};
ll n,m,l,r,ans;
ll delT;
ll delL,delR,delM;
vector<node> chunk;
void set(ll dl,ll dr,ll dm) {
delL=dl;
delR=dr;
delM+=dm;//因为可能同时完全覆盖多个
if(delL+delR+delM>=delT) {
delL=0;
delR=0;
delM=delT;
}
}
int main()
{
cin>>n>>m;
ans=n+1;
while(m--) {
cin>>l>>r;
l=max(1ll*0,l);
r=min(n,r);
delT=r-l+1;
delL=0,delR=0,delM=0;
for(ll i=0;i<chunk.size();i++) {
if(!chunk[i].allDel) {
ll lastL=chunk[i].l,lastR=chunk[i].r;
if(l<=lastL && r>=lastR) {//覆盖原有结构 (可能多个)
set(0,0,lastR-lastL+1);
chunk[i].l=l,chunk[i].r=r;
}
else if(l>=lastL && r<=lastR) {//完全重叠
set(0,0,delT);
chunk[i].allDel=1;
}
else if(l<lastL && r<=lastR && r>lastL) {//右侧重叠
set(0,r-lastL+1,0);
chunk[i].l=l;
}
else if(l>=lastL && r>lastR && l<lastR) {//左侧重叠
set(0,lastR-l+1,0);
chunk[i].r=r;
}
}
}
ll cnt=delL+delR+delM;
if(cnt==0) chunk.push_back({l,r,0}); //没有任何重叠
delT-=cnt;
ans-=delT;
}
cout<<ans;
}
这里空空如也
有帮助,赞一个