恭喜你找到了本场比赛的签到题! 为了让大家都有抽奖的机会,只需要复制粘贴以下代码(并且稍微填下空)即可 AC: (我超良心的) #include #include #include #include #include #include #include #include #include #include #include #include #include #define fi first #define lc (x= b;--i) #define SFOR(i,a,b,c) for(Re int i = a;i = b;i-=c) #define DEBUG(x) std::cerr L; inline int calc(){ 返回 set 中所有线段的并长度。(每个 pair 表示一个线段[first,second] } int main(){ scanf("%d%d",&N,&maxL); while(N--){ int opt,x,y; scanf("%d%d%d",&opt,&x,&y); if(opt == 1){ if(L.find(MP(x,y)) != L.end()) continue; L.insert(MP(x,y)); } if(opt == 2){ if(L.find(MP(x,y)) == L.end()) continue; L.erase(MP(x,y)); } if(opt == 3){ printf("%d\n",calc()); } } return 0; }
输入描述:
第一行两个整数 N,L,意义如代码所述。接下来 N 行,每行三个整数 opt,l,r,意义如代码所述。
输出描述:
对于每一组 opt=3 的询问输出一个答案。
示例1
输入
6 13
1 1 2
1 4 5
1 4 7
1 6 9
1 12 13
3 3 3
说明
我们依次加入线段[1,2],[4,5],[4,7],[6,9],[12,13], 它们的并集长度为 10.
备注:
,保证数据随机生成。
加载中...