Let $I\subseteq\mathbb N$ be finite and nonempty, $(E,\mathcal E,\lambda)$ be a $\sigma$-finite measure space, $$\lambda f:=\int f\:{\rm d}\lambda$$ for $\lambda$-integrable $f:E\to\mathbb R$, $p:E\to(0,\infty)$ be $\mathcal E$-measurable with $c:=\lambda p\in(0,\infty)$, $r:(I\times E)\times E\to[0,\infty)$ be $(2^I\otimes\mathcal E)\otimes\mathcal E$-measurable with $\lambda r((i,x),\;\cdot\;)=1$ for all $(i,x)\in I\times E$ and $g:E\to[0,\infty)$ be $\mathcal E$-measurable.
Given $x\in E$, how can we compute for which $i\in I$ the quantity $$\sigma_i:=\int\lambda({\rm d}y)\frac{\displaystyle\left|g(y)-\frac{p(y)}c\lambda g\right|^2}{r((i,x),y)}$$ is minimal (if there is more than one minimal $i$, I want to pick the smallest)? I'm not interested in the value of $\sigma_i$.
For the moment, I'm estimating each $\sigma_i$ using Monte Carlo integration (sampling from $r((i,x),\;\cdot\;)\lambda$ is possible) and then computing the smallest index $i$ whose corresponding estimate of $\sigma_i$ is minimal. However, this is error prone (since the estimate of $\sigma_i$ might be not close enough to $\sigma_i$) and extremely slow. The latter is my actual problem, since I need to solve this problem for $\approx1e5$ different $g$ inside a loop of range $\ge1e5$.
So, is there a smarter solution to this problem?
EDIT: Feel free to assume that $g$ is of the form $g=1_Hp$, where $H\in\mathcal E$ with $\lambda(H)\in(0,\infty)$. Under this assumption, $$\sigma_i=\left(c-2\lambda(1_Hp)\right)\int_H\mu({\rm d}y)\frac{p(y)}{r((i,x),y)}+\frac{\left|\lambda(1_Hp)\right|^2}c\int\mu({\rm d}y)\frac{p(y)}{r((i,x),y)}\tag1,$$ where $\mu:=c^{-1}p\lambda$. And you can assume that $$c-2\lambda(1_Hp)\ge0\tag2$$.