Double 思维+贪心

思维
贪心的搞每个数,每次增加1倍,最多30次就能大于所有的数,故直接暴力
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define fi first
#define se second
#define pb push_back
#define foa(x, y, z) for(int x = (y), ooo = (z); x <= z; ++x)
#define fos(x, y, z) for(int x = (y), ooo = (z); x >= z; --x)
#define ckmax(x, y) ((x) < (y) ? (x) = (y), 1 : 0)
#define ckmin(x, y) ((x) > (y) ? (x) = (y), 1 : 0)
typedef pair<int, int> pii;
typedef long long ll;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
int n, m;
int a[N];
void solve()
{
cin >> n;
foa(i, 1, n) cin >> a[i];
int mv = *max_element(a + 1, a + n + 1);
a[0] = a[n + 1] = inf;
vector<int> res;
foa(i, 1, n) {
int v = a[i], l = i - 1, r = i + 1;
while(v < mv) {
if(a[l] <= v) l--, v *= 2;
else if(a[r] <= v) r++, v *= 2;
else break;
}
if(v >= mv) res.pb(i);
}
cout << res.size() << endl;
for(auto &x : res) cout << x << " ";
cout << endl;
}
signed main()
{
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
solve();
return 0;
}

浙公网安备 33010602011771号