线段树


  先搞出来每个a[i]能连多少条边记为w[i]……如果对一组s[i],都满足w[i]-rank[i]>=0则这是一组合法方案,然后线段树维护w[i]-rank[i](第一个元素出去的时候后面所有的rank要-1,加入最后一个元素的时候后面的元素rank+1,建关于a[i]的权值线段树,记得离散化)

  线段树维护的时候modify(区间修改)忘加push_down了……so sad

 #include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std;
typedef long long LL;
inline int getint(){
int r=,v=; char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-')r=-;
for(; isdigit(ch);ch=getchar()) v=v*+ch-'';
return r*v;
}
const int N=,INF=~0u>>;
//#define debug
/********************template*******************/
struct node{
int size,min,add;
}t[N<<];
#define L (o<<1)
#define R (o<<1|1)
#define mid (l+r>>1)
int n,m,len,H,w[N],a[N],b[N],c[N];
void maintain(int o,int l,int r){
if (l==r) return;
t[o].size=t[L].size+t[R].size;
if (t[o].size) t[o].min=min(t[L].min,t[R].min);
else t[o].min=INF,t[o].add=;
}
int ql,qr;
void push_down(int o,int l,int r){
if (!t[o].add) return;
t[L].add+=t[o].add; t[R].add+=t[o].add;
t[L].min+=t[o].add; t[R].min+=t[o].add;t[o].add=;
}
void modify(int o,int l,int r,int num){
if (ql>qr) return;
if (ql<=l && qr>=r) t[o].add+=num,t[o].min+=num;
else{
push_down(o,l,r);
if (ql<=mid) modify(L,l,mid,num);
if (qr>mid ) modify(R,mid+,r,num);
maintain(o,l,r);
}
}
void update(int o,int l,int r,int pos,int rank){
if (l==r){
t[o].size^=;
t[o].min=t[o].size?w[pos]-rank-t[o].size:INF;
}else{
push_down(o,l,r);
if (a[pos]<=mid) update(L,l,mid,pos,rank);
if (a[pos]>mid) update(R,mid+,r,pos,rank+t[L].size);
maintain(o,l,r);
}
}
void out(int o,int l,int r){
printf("%d %d %d %d %d %d\n",
o,l,r,t[o].size,t[o].add,t[o].min);
if (l==r) return;
else {out(L,l,mid); out(R,mid+,r);}
}
inline bool cmp(int x,int y){return a[x]<a[y];}
int main(){
#ifndef ONLINE_JUDGE
freopen("CF338E.in","r",stdin);
freopen("CF338E.out","w",stdout);
#endif
n=getint(); len=getint(); H=getint();
F(i,,len) b[i]=getint();
sort(b+,b+len+);b[len+]=INF;
F(i,,n){
c[i]=i; a[i]=getint();
w[i]=len-(lower_bound(b+,b+len+,H-a[i])-b-);
}
sort(c+,c+n+,cmp);
F(i,,n) a[c[i]]=i;
F(i,,n*) t[i].min=INF;
F(i,,len){
ql=a[i]+; qr=n;
modify(,,n,-);
update(,,n,i,);
} #ifdef debug
F(i,,n) printf("%d %d\n",a[i],w[i]);
out(,,n);puts("");
#endif
int ans=t[].min>=;
F(i,len+,n){
ql=a[i-len]+; qr=n;
update(,,n,i-len,);
modify(,,n,); ql=a[i]+; qr=n;
update(,,n,i,);
modify(,,n,-);
if (t[].min>=) ans++;
#ifdef debug
printf("%d\n",i);
out(,,n);puts("");
#endif
}
printf("%d\n",ans);
return ;
}

【CodeForces】【338E】Optimize!的更多相关文章

  1. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  2. 【Codeforces Round #438 C】 Qualification Rounds

    [链接]h在这里写链接 [题意] 给你n个问题,每个人都知道一些问题. 然后让你选择一些问题,使得每个人知道的问题的数量,不超过这些问题的数量的一半. [题解] 想法题. 只要有两个问题. 这两个问题 ...

  3. 【Codeforces Round #438 B】Race Against Time

    [链接]h在这里写链接 [题意] 时针.分钟.秒针走不过去. 问你从t1时刻能不能走到t2时刻 [题解] 看看时针.分钟.秒针的影响就好. 看看是不是在整时的位置就好. 然后看看影响到x不能到y; 然 ...

  4. 【Codeforces Round #438 A】Bark to Unlock

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 枚举它是在连接处,还是就是整个字符串就好. [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc+ ...

  5. 【codeforces 718 C&D】C. Sasha and Array&D. Andrew and Chemistry

    C. Sasha and Array 题目大意&题目链接: http://codeforces.com/problemset/problem/718/C 长度为n的正整数数列,有m次操作,$o ...

  6. 【Codeforces 321E / BZOJ 5311】【DP凸优化】【单调队列】贞鱼

    目录 题意: 输入格式 输出格式 思路: DP凸优化的部分 单调队列转移的部分 坑点 代码 题意: 有n条超级大佬贞鱼站成一行,现在你需要使用恰好k辆车把它们全都运走.要求每辆车上的贞鱼在序列中都是连 ...

  7. 【codeforces contest 1119 F】Niyaz and Small Degrees

    题目 描述 \(n\) 个点的树,每条边有一个边权: 对于一个 \(X\) ,求删去一些边后使得每个点的度数 \(d_i\) 均不超过 \(X\) 的最小代价: 你需要依次输出 \(X=0 \to n ...

  8. 【codeforces #282(div 1)】AB题解

    A. Treasure time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...

  9. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  10. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

随机推荐

  1. 删除linux系统服务

    #删除服务的命令,[ServiceName]需要替换为实际的服务名称 sudo update-rc.d [ServiceName] remove 有时候安装sysv-rc-conf进行服务控制,但是在 ...

  2. C(++)基于websocket实时通信的实现—GoEasy

    c(++) websocket实时消息推送 在这里我记录一下之前如何实现服务器端与客户端实时通信: 实现步骤如下: 1.        获取GoEasy appkey. 在goeasy官网上注册一个账 ...

  3. 电商、商城类APP常用标签"hot"--第三方开源--LabelView

    LabelView是在github上一个开源的标签库.其项目主页是:https://github.com/linger1216//labelview LabelView为一个TextView,Imag ...

  4. 用FileInputStream读文件,字节数组接收,不知道文件的大小时怎么办

    FileInputStream in = new FileInputStream(文件路径File); byte[] buffer = new byte[in.available()]; in.rea ...

  5. SQL Server 基础:Cast和Convert的区别

    CAST 和 CONVERT 都可以将某种数据类型的表达式显式转换为另一种数据类型. 语法: CAST ( expression AS data_type ) CONVERT (data_type[( ...

  6. [转]Posix-- 互斥锁 条件变量 信号量

    这是一个关于Posix线程编程的专栏.作者在阐明概念的基础上,将向您详细讲述Posix线程库API.本文是第三篇将向您讲述线程同步. 互斥锁 尽管在Posix Thread中同样可以使用IPC的信号量 ...

  7. webpack 学习笔记 02 快速入门

    webpack 的目标 将依赖项分块,按需加载. 减少web app的初始加载时间. 使每一个静态集合都能够作为组件使用. 有能力集成第三方库,作为组件使用. 高度可配置化. 适用于大型项目. INS ...

  8. StyleCop学习笔记——默认的规则

    在StyleCop中有一些官方自己写好的检测规则下面就是英文的解释 文档规则 1.SA1600:ElementsMustBeDocumented元素必须添加注释 2.SA1601: PartialEl ...

  9. oracle 临时表空间

    环境: OS: Oracle Linux Server release 5.7 DB: Oracle Database 11g Enterprise Edition Release 11.2.0.3. ...

  10. 分享我常用的一些JS验证和函数

    下面是我常用一些JS验证和函数,有一些验证我直接写到了对象的属性里面了,可以直接通过对象.方法来调用//浮点数除法运算 function fdiv(a, b, n) { if (n == undefi ...