1 条题解
-
0
向右仰望(Look Up S) 题解
思路分析
按题目要求使用对应数据结构与算法模拟/递推求解,注意数据范围边界与时间复杂度。
参考代码
#include <iostream> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; if (!(cin >> n)) return 0; vector<int> h(n + 1), ans(n + 1, 0), stk; for (int i = 1; i <= n; ++i) cin >> h[i]; for (int i = n; i >= 1; --i) { while (!stk.empty() && h[stk.back()] <= h[i]) stk.pop_back(); ans[i] = stk.empty() ? 0 : stk.back(); stk.push_back(i); } for (int i = 1; i <= n; ++i) cout << ans[i] << "\n"; return 0; }
- 1
信息
- ID
- 8630
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者