单调栈真的很好用呢! P2947 [USACO09MAR]向右看齐Look Up 题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Cow i has height H_i (1 <= H_i <= 1,000,000). Each cow is looking to her left toward those wi…
题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Cow i has height H_i (1 <= H_i <= 1,000,000). Each cow is looking to her left toward those with higher index numbers. We say that cow…
目录 题目 思路 \(Code\) 题目 戳 思路 单调栈裸题 \(Code\) #include<stack> #include<cstdio> #include<string> #include<cstring> #include<iostream> #define MAXN 100001 #define rr register using namespace std; int n,ans[MAXN]; struct mu{ int num,…
题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Cow i has height H_i (1 <= H_i <= 1,000,000). Each cow is looking to her left toward those with higher index numbers. We say that cow…
题目链接:https://www.luogu.org/problemnew/show/P2947 因为在单调队列上被dalao们锤爆 怒刷单调队列题 何为单调队列? 设我们的队列为从左至右单调递增 对于样例数据 3 2 6 1 1 2 我们先把3入队 此时队列:3 再将2从后面入队 此时队列:2 3 再将6从后面入队 但是,为了满足队列从左至右的单调性,我们将2,3出队 此时队列:6 再将1从后面入队 此时队列:1 6 再将1从后面入队 此时队列:1 1 6 再将2从后面入队 但是,为了满足队列…
#include<cstdio> #include<algorithm> #include<stack> #include<cctype> using namespace std; struct cow{ int id; int data; cow(,):id(id),data(data){ } }ans[]; stack<cow> q; int n,tmp,cnt; inline bool cmp(const cow &a,const…
https://www.luogu.org/problem/P2947 题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Cow i has height Hi (1 <= Hi <= 1,000,000). Each cow is looking to her left toward those with high…
P2947 [USACO09MAR]仰望Look Up 74通过 122提交 题目提供者洛谷OnlineJudge 标签USACO2009云端 难度普及/提高- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 中文翻译应当为向右看齐 题目中文版范围.. 题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again standing in a row. Co…
向右看齐 题目链接 此题可用单调栈O(n)求解 维护一个单调递减栈,元素从左到右入栈 若新加元素大于栈中元素,则栈中元素的仰望对象即为新加元素 每次将小于新加元素的栈中元素弹出,记录下答案 #include<iostream> #include<cstdio> using namespace std; #define N 100010 int n,w[N],stack[N],top,ans[N]; int main() { scanf("%d",&n);…
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 8748  Solved: 3835[Submit][Status][Discuss] Description 现在请求你维护一个数列,要求提供以下两种操作:1. 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度.2. 插入操作.语法:A n 功能:将n加上t,其中t是最近一次查询…