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

Topic: https://nanti.jisuanke.com/t/41399

Ideas: the difference array interval of the odd number of times the lamp is operated as an open state

#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;
}

Guess you like

Origin www.cnblogs.com/c4Lnn/p/12090696.html