The Preliminary Contest for ICPC Asia Shanghai 2019 B. Light bulbs

题目:https://nanti.jisuanke.com/t/41399

思路:差分数组 区间内操作次数为奇数次则灯为打开状态

#include
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)
        {
            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)