cf1000 C. Covered Points Count

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll ,int > mp;
ll cnt[200010];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        ll l,r;
        scanf("%lld%lld",&l,&r);
        mp[l]++;
        mp[r+1]--;
    }
    ll start;
    int num=0;
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        if(it==mp.begin())
        {
            start=it->first;
            num+=it->second;
        }
        else
        {
            //printf("%d %d\n",num,(it->first) - start);
            cnt[num]+=( (it->first) - start);//cnt记录的是点的个数,所以会爆int!!!
            start=(it->first);
            num+=it->second;
        }
    }
    for(int i=1;i<=n;i++)
       printf("%lld ",cnt[i]);
    printf("\n");
}

前缀和的变体。

原文地址:https://www.cnblogs.com/lishengkangshidatiancai/p/10348100.html

时间: 2024-10-17 04:22:35

cf1000 C. Covered Points Count的相关文章

Covered Points Count(思维题)

C. Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given nn segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segment

Codeforces 1000C Covered Points Count

C. Covered Points Count题目大意:有n条线段,问有多少个点被i条线段覆盖(i=1~n).很常见的线段覆盖套路题QAQ.坐标排序后把左端点当做+1,右端点当做-1,扫一遍统计答案即可.但是记得开ll,数组大小开双倍. 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cmath> 5 #include <queue> 6 #

Covered Points Count CF1000C 思维 前缀和 贪心

Covered Points Count time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given nn segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments c

Educational Codeforces Round 46 C - Covered Points Count

C - Covered Points Count emmm 好像是先离散化一下 注意 R需要+1 这样可以确定端点 emmm 扫描线?瞎搞一下? #include<bits/stdc++.h> using namespace std; #define maxn 4000005 #define LL long long LL a[maxn],b[maxn],ll[maxn],rr[maxn],c[maxn]; LL x[maxn],y[maxn]; vector<LL >q; int

EDU 50 E. Covered Points 利用克莱姆法则计算线段交点

E. Covered Points 利用克莱姆法则计算线段交点.n^2枚举,最后把个数开方,从ans中减去. ans加上每个线段的定点数, 定点数用gcs(△x , △y)+1计算. #include <algorithm> #include <iterator> #include <iostream> #include <cstring> #include <cstdlib> #include <iomanip> #include

[CodeForces-1036E] Covered Points 暴力 GCD 求交点

题意: 在二维平面上给出n条不共线的线段,问这些线段总共覆盖到了多少个整数点 解法: 用GCD可求得一条线段覆盖了多少整数点,然后暴力枚举线段,求交点,对于相应的 整数交点,结果-1即可 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 #include<cmath> 6 #include<vector> 7 #inc

差分简单题集

[一维差分]Codeforces 1000C Covered Points Count 题目大意: 给定$n$个线段,给定这些线段所在的区间($l,r\leq10^{18}$),这些线段能够覆盖它们所包含的点,问你被包含$[1,n]$次的点分别有多少个. 解题分析:用差分来高效的统计一下指定区间内所被覆盖的线段个数,同时,因为$l,r$的大小非常大,所以我们需要对所有的线段进行离散化. #include <bits/stdc++.h> using namespace std; template

[Swift]LeetCode149. 直线上最多的点数 | Max Points on a Line

Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. Example 1: Input: [[1,1],[2,2],[3,3]] Output: 3 Explanation: ^ | |        o |     o |  o   +-------------> 0  1  2  3 4 Example 2: Input: [[1,1],[3,2]

Oracle E-Business Suite Maintenance Guide Release 12.2(Patching Procedures)

更多内容参考: http://docs.oracle.com/cd/E51111_01/current/acrobat/122ebsmt.zip Preparing for Patching For patches that have manual steps, the patch readme file instructs you to use Oracle Patch Application Assistant (PAA) to create customized instructions