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

Posted c4lnn

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The Preliminary Contest for ICPC Asia Shanghai 2019 B. Light bulbs相关的知识,希望对你有一定的参考价值。

题目: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
",i,res);
    }
    return 0;
}

以上是关于The Preliminary Contest for ICPC Asia Shanghai 2019 B. Light bulbs的主要内容,如果未能解决你的问题,请参考以下文章

The Preliminary Contest for ICPC Asia Yinchuan 2019

The Preliminary Contest for ICPC Asia Shenyang 2019

The Preliminary Contest for ICPC Asia Shanghai 2019

The Preliminary Contest for ICPC Asia Shanghai 2019

The Preliminary Contest for ICPC Asia Xuzhou 2019

The Preliminary Contest for ICPC Asia Nanchang 2019