题目描述 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,…
#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…
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);…
题目描述 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…
单调栈真的很好用呢! 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…
题目链接: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从后面入队 但是,为了满足队列…
题目描述 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…
题目传送门 大概思路就是把这两个数组排序.在扫描一次,判断大小,累加ans. #include<bits/stdc++.h> using namespace std; int x,y,z; ],m[]; long long s; int main(){ cin>>z>>x>>y; ;i<=z;i++) cin>>n[i]>>m[i]; sort(n+,n++z); sort(m+,m++z); ;i<=z;i++){ if…