【链接】 我是链接,点我呀:)

【题意】

【题解】

对于每个i,用二分的方法求出来y所在的位置j.
可以这样求。
假设现在二分到了位置mid.
那么随便用个rmq求出来mid..n这一段的最小值temp。
看看temp是否满足

【代码】

#include <bits/stdc++.h>
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define LL long long
using namespace std; const int N = 1e5; int n;
int a[N+10];
int mi[N+10][17+5]; int get_mi(int l,int r){
int len = log2(r-l+1);
return min(mi[l][len],mi[r-(1<<len)+1][len]);
} int main()
{
//freopen("D:\\rush.txt","r",stdin);
scanf("%d",&n);
rep1(i,1,n) scanf("%d",&a[i]);
rep1(i,1,n) mi[i][0] = a[i];
rep1(l,1,17)
rep1(i,1,n){
int j = i+(1<<l)-1;
if (j>n) break;
mi[i][l] = min(mi[i][l-1],mi[i+(1<<(l-1))][l-1]);
}
rep1(i,1,n){
int l = i,r = n,temp = -1;
while (l<=r){
int mid = (l+r)>>1;
if (get_mi(mid,n)<a[i]){
temp = mid;
l = mid + 1;
}else
r = mid - 1;
}
if (temp==-1){
printf("-1");
}else{
printf("%d",temp-i-1);
}
if(i==n)puts("");else putchar(' ');
}
return 0;
}

【Codeforces 91B】Queue的更多相关文章

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

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

  2. 【codeforces 767B】The Queue

    [题目链接]:http://codeforces.com/contest/767/problem/B [题意] 排队去办护照; 给你n个人何时来的信息; 然后问你应该何时去才能在队伍中等待的时间最短; ...

  3. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

  4. 【codeforces 510C】Fox And Names

    [题目链接]:http://codeforces.com/contest/510/problem/C [题意] 给你n个字符串; 问你要怎么修改字典序; (即原本是a,b,c..z现在你可以修改每个字 ...

  5. 【codeforces 796D】Police Stations

    [题目链接]:http://codeforces.com/contest/796/problem/D [题意] 在一棵树上,保证每个点在距离d之内都有一个警察局; 让你删掉最多的边,使得剩下的森林仍然 ...

  6. 【codeforces 716D】Complete The Graph

    [题目链接]:http://codeforces.com/problemset/problem/716/D [题意] 给你一张图; 这张图上有一些边的权值未知; 让你确定这些权值(改成一个正整数) 使 ...

  7. 【codeforces 505D】Mr. Kitayuta's Technology

    [题目链接]:http://codeforces.com/problemset/problem/505/D [题意] 让你构造一张有向图; n个点; 以及所要求的m对联通关系(xi,yi) 即要求这张 ...

  8. 【codeforces 95C】Volleyball

    [题目链接]:http://codeforces.com/problemset/problem/95/C [题意] 给你n个点,m条边; 每个点有一辆出租车; 可以到达离这个点距离不超过u的点,且在这 ...

  9. 【19.77%】【codeforces 570D】Tree Requests

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. .Net-ASP.NET Web API:目录

    ylbtech-.Net-ASP.NET Web API:目录 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. https://www.asp.net/we ...

  2. 0423-mysql查询语句大全

    建表.数据插入代码: #新建学生表 drop table if exists student; create table student( sno ) not null primary key com ...

  3. 函数中的this的四种绑定形式

    目录 this的默认绑定 this的隐式绑定 隐式绑定下,作为对象属性的函数,对于对象来说是独立的 在一串对象属性链中,this绑定的是最内层的对象 this的显式绑定:(call和bind方法) n ...

  4. css 画箭头

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  5. centos 修改网卡信息命令

    vi /etc/sysconfig/network-scripts/ifcfg-eth0

  6. xhtml1-strict.dtd

    <!-- Extensible HTML version 1.0 Strict DTD This is the same as HTML 4 Strict except for changes ...

  7. Spring Cloud (3) 服务消费者-Ribbon

    在上一篇中使用LoadBalancerClient接口实现了获取某个服务的具体实例,并根据实例信息发起服务接口消费请求.但是这样的做法需要我们手工的区编写服务选取.连接拼接等繁琐的工作,对于开发人员来 ...

  8. Spring Boot (9) mybatis全注解化

    ORM对比图 框架对比 Spring JDBC Spring Data Jpa Mybatis 性能 性能最好 性能最差 居中 代码量 多 少 多 学习成本 低 高 居中 推荐指数 ❤❤❤ ❤❤❤❤❤ ...

  9. Entity Framework -- 添加,删除,修改,关系依附,关系摘除,验证操作

    数据库模型 这个基本上是浓缩 Jerry Tom博客的内容,作为参考http://www.cnblogs.com/mbailing/archive/2012/07/31/2616779.html 说明 ...

  10. canvas 和 svg

    对于开发人员而言,最直观的区别在于:1.对于画在Canvas上的部件,你需要处理重绘.而SVG则不用,你修改svg dom则系统会自动帮你重绘2.Hittest,即canvas不负责帮你侦测鼠标/触摸 ...