Atcoder regular Contest 073(C - Sentou)

传送门

每个人对开关的影响区间为a[i]--a[i]+t,因此此题即为将所有区间离散化后求所有独立区间的长度和

#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1000000000LL
#define mod 1000000007
using namespace std;
int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
const int N=2e5+10;
pair<ll,ll> B[N*2];
int main()
{
// while(true)
{
int n=read(),t=read();
int top=0;
ll x;
for(int i=0;i<n;i++)
{
x=read();
B[top].first=x;
B[top].second=-1;
top++;
// cout<<x+t<<endl;
B[top].first=x+t;
B[top].second=1;
top++;
}
sort(B,B+top);
int count=0;
ll pre=0,ans=0;
bool first=1;
for(int i=0;i<top;i++)
{
if(B[i].second==1){
count++;
if(count==0){
ans+=B[i].first-pre;
}
}
if(B[i].second==-1){
count--;
if(count==-1){
pre=B[i].first;
}
}
}
printf("%I64d\n",ans);
}
return 0;
}

Atcoder regular Contest 073(C - Sentou)的更多相关文章

  1. Atcoder regular Contest 073(D - Simple Knapsack)

    Atcoder regular Contest 073(D - Simple Knapsack) 传送门 因为 w1≤wi≤w1+3 这个特殊条件,我们可以将每个重量离散化一下,同时多开一维记录选择的 ...

  2. AtCoder Regular Contest 073 E:Ball Coloring

    题目传送门:https://arc073.contest.atcoder.jp/tasks/arc073_c 题目翻译 给你\(N\)个袋子,每个袋子里有俩白球,白球上写了数字.对于每一个袋子,你需要 ...

  3. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

  4. AtCoder Regular Contest 094 (ARC094) CDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...

  5. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

  6. AtCoder Regular Contest 093

    AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...

  7. AtCoder Regular Contest 094

    AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...

  8. AtCoder Regular Contest 095

    AtCoder Regular Contest 095 C - Many Medians 题意: 给出n个数,求出去掉第i个数之后所有数的中位数,保证n是偶数. \(n\le 200000\) 分析: ...

  9. AtCoder Regular Contest 102

    AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...

随机推荐

  1. ROS学习笔记一:ROS安装与测试

    1 Ubuntu和ROS版本的对应关系 Ubuntu 和 ROS 都存在不同的版本,其对应关系如下: 注:如果Ubuntu版本和ROS版本不对应的话,安装就不会成功了- 笔者安装的是Ubuntu14. ...

  2. BZOJ2553 [BJWC2011]禁忌

    传送门 Description ​ 给你前alphabet个小写字母组成的字符集, 以及n个单词, 定义一个串s的禁忌值为 \(\sum_{i } [s[i] == Taboo[i]]\) , Tab ...

  3. Service官方教程(10)Bound Service的生命周期函数

    Managing the Lifecycle of a Bound Service When a service is unbound from all clients, the Android sy ...

  4. synchronized(4)修饰语句块之:synchronized(this)

    synchronized(this) 此时,线程获得的是对象锁.例如: public class Thread8 extends Thread { public void sync_fun() { s ...

  5. Hackonacci Matrix Rotations 观察题 ,更新了我的模板

    https://www.hackerrank.com/contests/w27/challenges/hackonacci-matrix-rotations 一开始是没想到观察题的.只想到直接矩阵快速 ...

  6. Tcpdump的用法

    见 超级详细Tcpdump 的用法 http://www.itshouce.com.cn/linux/linux-tcpdump.html

  7. [转]ASP.NET MVC 3 Application Upgrader

    本文转自:http://aspnet.codeplex.com/releases/view/59008 Recommended Download      ASP.NET MVC 3 Applicat ...

  8. LN : leetcode 312 Burst Balloons

    lc 312 Burst Balloons 312 Burst Balloons Given n balloons, indexed from 0 to n-1. Each balloon is pa ...

  9. CentOS7.5搭建LAMP环境

    导言 LAMP环境搭建,网上可以搜到很多的结果.为什么我还要整理一下呢,是因为有些网上给出的解决办法可能仅适用于某些特定的环境下,并不一定适用于所有出现问题的情况. 当然我写本篇的目的也不是保证所有的 ...

  10. linux 安装 mongo 3.4

    要求:linux 安装 mongo 3.4 大体上,按照官网提供的方法来做. 系统是ubuntu 16.04 安装的是mongo3.4.8 社区版 1.         导入导入包管理系统使用的公钥 ...