Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) (x).begin(),(x).end()
- using namespace std;
- using ll = long long;
- vector<int> Solve(vector<int>& arr) {
- const int n = arr.size();
- vector<int> l(n);
- for (int i = 0; i < n; i++) {
- l[i] = i;
- while (l[i] > 0 && arr[l[i] - 1] >= arr[i]) {
- l[i] = l[l[i] - 1];
- }
- }
- return l;
- }
- int main() {
- const int n = 10;
- vector<int> arr(n);
- for (int i = 0; i < n; i++) {
- arr[i] = rand() % 50;
- }
- auto l = Solve(arr);
- reverse(all(arr));
- auto r = Solve(arr);
- reverse(all(r));
- for (int i = 0; i < n; i++) {
- r[i] = n - 1 - r[i];
- }
- ll ans = 0;
- reverse(all(arr));
- for (int i = 0; i < n; i++) {
- ans = max(ans, 1ll * (r[i] - l[i] + 1) * arr[i]);
- }
- for (int i = 0; i < n; i++) {
- cout << arr[i] << ' ' << l[i] << ' ' << r[i] << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement