inlinevoidInput(){ read(n, p); for(int i = 1; i <= n; i++) { read(a[i]); } }
int stk[N], top; int ls[N], rs[N], rt;
ll sum[N]; ll ans;
inline ll Calc(int l, int r, int h){ h++; l = max(l, (int)((p + h - 1) / h)); if(l <= r) return1LL * h * (r - l + 1) - sum[r] + sum[l - 1]; elsereturn0; }
voidDfs(int u, int l, int r){ if(u == 0) return ; // cout << u << ' ' << ls[u] << endl << u << ' ' << rs[u] << endl; Dfs(ls[u], l, u - 1), Dfs(rs[u], u + 1, r); int szL = u - l + 1, szR = r - u + 1; if(szL > szR) swap(szL, szR); for(int i = 1; i <= szL; i++) ans += Calc(i, i + szR - 1, a[u]); }
inlinevoidWork(){ for(int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (p + i - 1) / i; for(int i = 1; i <= n; i++) { int k = top; while(k > 0 && a[i] < a[stk[k]]) k--; if(k) rs[stk[k]] = i; else rt = i; if(k < top) ls[i] = stk[k + 1]; stk[++k] = i; top = k; } Dfs(rt, 1, n); printf("%lld\n", ans); }
intmain(){ int T = 1; while(T--) { Input(); Work(); } return0; }