标签:https map first main sha mes pre anti cond
题目:https://nanti.jisuanke.com/t/41399
思路:差分数组 区间内操作次数为奇数次则灯为打开状态
#include<bits/stdc++.h> using namespace std; map<int,int>mp; int main() { int T; scanf("%d",&T); int n,m; int l,r; for(int i=1;i<=T;i++) { mp.clear(); scanf("%d%d",&n,&m); for(int i=0;i<m;i++) { scanf("%d%d",&l,&r); mp[l]++,mp[r+1]--; } int sum=0,res=0,pre; for(auto y:mp) if(y.second) { if(sum&1) res+=y.first-pre; sum+=y.second; pre=y.first; } printf("Case #%d: %d\n",i,res); } return 0; }
The Preliminary Contest for ICPC Asia Shanghai 2019 B. Light bulbs
标签:https map first main sha mes pre anti cond
原文地址:https://www.cnblogs.com/c4Lnn/p/12090696.html