求大佬解惑

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

5ooii7 @ 2023-10-20 18:06:26

到底是哪的问题?

#include <bits/stdc++.h>
using namespace std;

int l,m;
int u,v;

int main(){
//  freopen("123.txt","r",stdin);
//  freopen("123.txt","w",stdout);
    scanf("%d%d",&l,&m);
    int cut=0;
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        l-=v-u;
        cout<<l<<endl;
    }
    printf("%d",l);
    return 0;
}

by Gch738 @ 2023-10-20 18:08:01

删除的区间有重合,在代码中重合区间被重复计算


by Gch738 @ 2023-10-20 18:09:34

可以用一个数组标记已被删除的数,删除时检查该位置是否已被删除


by 5ooii7 @ 2023-10-21 15:00:35

谢谢 @Gch738


|