Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count

Bryce1010模板
http://codeforces.com/problemset/problem/1000/C

题意:问你从[l,r]区间的被多少条线覆盖,列出所有答案。
思路:类似括号匹配的做法

#include 

using namespace std;

#define ll long long


const ll MAXN=2e5+10;
struct Node
{
    ll num;
    ll dir;//0左1右
    //ll cnt;
}node[MAXN*2];
ll cnt[MAXN*2];

bool cmp(Node a,Node b)
{
    if(a.num!=b.num)return a.numelse return a.dirint main()
{
    ll n;
    cin>>n;
    for(ll i=0;i<2*n;i++)
    {
        if(i&1)
        {
            cin>>node[i].num;
            node[i].dir=1;
        }
        else
        {
            cin>>node[i].num;
            node[i].dir=0;
        }
    }
    sort(node,node+2*n,cmp);
//    for(ll i=0;i<2*n;i++)
//        cout<

    ll tot=0;
    for(ll i=0;i<2*n;i++)
    {
        if(node[i].dir==0)//左
        {
            if(node[i-1].dir==0)
                cnt[tot]+=node[i].num-node[i-1].num;
            else if(node[i-1].dir==1)
                cnt[tot]+=node[i].num-node[i-1].num-1;
            tot++;
        }
        else//右
        {
            if(node[i-1].dir==1)
                cnt[tot]+=node[i].num-node[i-1].num;
            else
                cnt[tot]+=node[i].num-node[i-1].num+1;
            tot--;
        }


    }

    cout<1];
    for(ll i=2;i<=n;i++)
        cout<<" "<cout<return 0;
}

你可能感兴趣的:(Educational Codeforces Round 46 (Rated for Div. 2) C. Covered Points Count)