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

【题意】

【题解】

对于每个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. HTML5开发移动web应用——SAP UI5篇(7)

    SAPUI5中支持利用Component对组件进行封装.想封装一个组件,Component的基本代码例如以下: sap.ui.define([ "sap/ui/core/UIComponen ...

  2. 复习--最小生成树&&并查集

    我个人比较喜欢Kruskal算法,所以就把这个方法写了一下,但过不了洛谷,70分. 思路是先全读入,再排序,一条一条加边.运用并查集. #include<iostream> #includ ...

  3. Coursera Algorithms week1 算法分析 练习测验: Egg drop 扔鸡蛋问题

    题目原文: Suppose that you have an n-story building (with floors 1 through n) and plenty of eggs. An egg ...

  4. Thinkpad E450c进入BIOS

    重启系统,一直按F12,进入系统设置后,按tab进入App Menu选项卡,选择Setup按回车进入BIOS设置

  5. js form settimeout

    <html><head><meta charset="utf8"><script type="text/javascript&q ...

  6. 原生JS---5

    原生js学习笔记5——BOM操作 什么是BOM BOM:Browser Object Model 是浏览器对象模型,浏览器对象模型提供了独立与内容的.可以与浏览器窗口进行互动的对象结构,BOM由多个对 ...

  7. Android开发利器之ActivityTracker

    版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/113 Android开发利器之ActivityTracke ...

  8. C++中const用法

    1.const和指针: 如果const出现在星号左边,表示被指物是常量:如果出现在星号右边,表示指针自身是常量:如果出现在星号两边,表示被指物和指针两者都是常量. char greet[] = “He ...

  9. [编码]ASCII、GBK、Unicode(万国码) 和 UTF-8

    American ASCII编码 (American Standard Code for Information Interchange,美国信息互换标准代码)  China    gbk编码     ...

  10. 设计模式之桥接模式(Java语言描述)

    桥接模式定义 將抽象部分与它的具体实现部分分离,使它们都可以独立地变化.它是一种对象结构型模式,又称为柄体模式或接口模式. Decouple an abstraction from its imple ...