P2866 [USACO06NOV]糟糕的一天Bad Hair Day 75通过 153提交 题目提供者洛谷OnlineJudge 标签USACO2006云端 难度普及/提高- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 题目标题 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her…
题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads. Each cow i has a specified…
题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows' heads. Each cow i has a specified…
https://www.luogu.org/problem/show?pid=2866 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of o…
链接:https://ac.nowcoder.com/acm/contest/984/A 来源:牛客网 题目描述 Some of Farmer John's N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the…
传送门 这是一道典型的单调栈. 题意理解 先来理解一下题意(原文翻译得有点问题). 其实就是求对于序列中的每一个数i,求出i到它右边第一个大于i的数之间的数字个数c[i].最后求出和. 首先可以暴力求解,时间复杂度o(n^2)显然TLE. 然后就是用单调栈来做. 单调栈 单调栈就是维护一个栈,使得栈中的元素是单调的(递增/递减). 假设是递减——对于每一个新来的元素,把栈顶大于这个元素的每一个数字全部弹出,最后把这个元素加进去. (如果栈为空,直接加入) 单调栈有什么用呢? 单调递增栈能以o(n…
[题意概述] 给出一个长度为n的序列a,求有多少对[i,j]满足i<j且a[i]>max(a[i+1],a[i+2],...,a[j]). [题解] 单调栈. 倒着处理序列的元素,维护一个单调递减的栈,同时记录栈中的每个元素进栈的时间.如果当前元素x大于栈顶元素,那么栈顶到第二个元素在原素列之间的这一段就都是可以被x看见的,答案加上time[top]-time[top-1]. #include<cstdio> #include<algorithm> #include&l…
看到这道题很容易想到单调栈,但我一开始想的是从后往前扫,但发现会有问题(因为这样会对后面牛的答案造成影响),所以这时我们要及时换一个思路,从前往后扫. 维护一个单调递减的栈,插入h[i]时,小等于它的数都要出栈,累加栈中元素数量,表示的意义就是:当前栈中的牛都是可以看到i这头牛的,即他们不会被i这头牛挡住. 1 #include<bits/stdc++.h> 2 using namespace std; 3 long long ans,h[80010]; 4 int s[80010],top,…
P2866 [USACO06NOV]糟糕的一天Bad Hair Day 题意翻译 农夫约翰有N (N \leq 80000)N(N≤80000)头奶牛正在过乱头发节.每一头牛都站在同一排面朝东方,而且每一头牛的身高为h_ihi​.第NN头牛在最前面,而第11头牛在最后面. 对于第ii头牛前面的第jj头牛,如果h_i>h_{i+1}hi​>hi+1​并且h_i>h_{i+2}hi​>hi+2​ \cdots⋯ h_i>h_jhi​>hj​,那么认为第ii头牛可以看到第i+…
P2866 [USACO06NOV]糟糕的一天Bad Hair Day 奶牛题里好多单调栈..... 维护一个单调递减栈,存每只牛的高度和位置,顺便统计一下答案. #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define N 80010 int n,tp,q[N],h[N]; long long ans; int main(){ scanf("%d&qu…