RMQ Codeforces Round #322 (Div. 2) B. Luxurious Houses
2015-09-28 22:01
483 查看
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #include<cstdlib> #include<map> #include<queue> #include <deque> #include <list> #include <ctime> #include <stack> #include <vector> #include<set> #define Maxn 222222 #define MOD typedef long long ll; #define FOR(i,j,n) for(int i=j;i<=n;i++) #define DFR(i,j,k) for(int i=j;i>=k;--i) #define lowbit(a) a&-a #define FOR(i,j,n) for(int i=j;i<=n;i++) #define DFR(i,j,k) for(int i=j;i>=k;--i) #define lowbit(a) a&-a #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); int counter=1; using namespace std; int MAX[Maxn<<2],height[Maxn<<2]; void PushUP(int rt) { MAX[rt]=max(MAX[rt<<1],MAX[rt<<1|1]); } void build(int l,int r,int rt) { if(l==r) {scanf("%d",&MAX[rt]);height[counter++]=MAX[rt];return;} int m=(l+r)>>1; build(lson); build(rson); PushUP(rt); } int query(int L,int R,int l,int r,int rt) { if(L<=l&&r<=R) return MAX[rt]; int m = (l+r)>>1; int ret=0; if(L<=m) ret = max(ret,query(L,R,lson)); if(R>m) ret = max(ret,query(L,R,rson)); return ret; } int main() { int n; while(~scanf("%d",&n)) { build(1,n,1); FOR(i,1,n-1) { printf("%d ",query(i,n,1,n,1)==height[i]&&height[i]>query(i+1,n,1,n,1)?0:query(i,n,1,n,1)-height[i]+1); } printf("0\n"); } return 0; }
相关文章推荐
- 通过 poj3368 问题讨论:RMQ问题的 tarjan_lca 求解
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- Codeforces Round #265 (Div. 2)
- Codeforces #310 div2 C. Case of Matryoshkas
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish
- Codeforces round #247 for Div. 2
- Codeforces Round #246 (Div. 2)
- Codeforces #264(div 2)D.Gargari and Permutations
- Codeforces Round #236 (Div. 2)------A,B
- codeforces 257 div2 B
- Codeforces Gym100571A Cursed Query
- Codeforces Gym100342E Minima
- Codeforces Gym100342J Triatrip
- Codeforces Gym100286B Blind Walk (dfs)