hcju/stacksqa huggingface dataset:
We will use that the homotopy category $K(\textit{Mod}(\mathcal{O}_X))$ is a triangulated category, see Derived Categories, Proposition \ref{derived-proposition-homotopy-category-triangulated}. Choose a distinguished triangle $\mathcal{K}^\bullet \to \mathcal{L}^\bullet \to \mathcal{C}^\bullet \to \mathcal{K}^\bullet[1]$. Choose a quasi-isomorphism $\mathcal{M}^\bullet \to \mathcal{C}^\bullet$ with $\mathcal{M}^\bullet$ K-flat with flat terms, see Lemma \ref{lemma-K-flat-resolution}. By the axioms of triangulated categories, we may fit the composition $\mathcal{M}^\bullet \to \mathcal{C}^\bullet \to \mathcal{K}^\bullet[1]$ into a distinguished triangle $\mathcal{K}^\bullet \to \mathcal{N}^\bullet \to \mathcal{M}^\bullet \to \mathcal{K}^\bullet[1]$. By Lemma \ref{lemma-K-flat-two-out-of-three} we see that $\mathcal{N}^\bullet$ is K-flat. Again using the axioms of triangulated categories, we can choose a map $\mathcal{N}^\bullet \to \mathcal{L}^\bullet$ fitting into the following morphism of distinghuised triangles $$ \xymatrix{ \mathcal{K}^\bullet \ar[r] \ar[d] & \mathcal{N}^\bullet \ar[r] \ar[d] & \mathcal{M}^\bullet \ar[r] \ar[d] & \mathcal{K}^\bullet[1] \ar[d] \\ \mathcal{K}^\bullet \ar[r] & \mathcal{L}^\bullet \ar[r] & \mathcal{C}^\bullet \ar[r] & \mathcal{K}^\bullet[1] } $$ Since two out of three of the arrows are quasi-isomorphisms, so is the third arrow $\mathcal{N}^\bullet \to \mathcal{L}^\bullet$ by the long exact sequences of cohomology associated to these distinguished triangles (or you can look at the image of this diagram in $D(\mathcal{O}_X)$ and use Derived Categories, Lemma \ref{derived-lemma-third-isomorphism-triangle} if you like). This finishes the proof of (1), (2), and (3). To prove the final assertion, we may choose $\mathcal{N}^\bullet$ such that $\mathcal{N}^n \cong \mathcal{M}^n \oplus \mathcal{K}^n$, see Derived Categories, Lemma \ref{derived-lemma-improve-distinguished-triangle-homotopy}. Hence we get the desired flatness if the terms of $\mathcal{K}^\bullet$ are flat.
To see this we use the general theory developed in Derived Categories, Section \ref{derived-section-derived-functors}. Set $\mathcal{D} = K(\mathcal{O}_Y)$ and $\mathcal{D}' = D(\mathcal{O}_X)$. Let us write $F : \mathcal{D} \to \mathcal{D}'$ the exact functor of triangulated categories defined by the rule $F(\mathcal{G}^\bullet) = f^*\mathcal{G}^\bullet$. We let $S$ be the set of quasi-isomorphisms in $\mathcal{D} = K(\mathcal{O}_Y)$. This gives a situation as in Derived Categories, Situation \ref{derived-situation-derived-functor} so that Derived Categories, Definition \ref{derived-definition-right-derived-functor-defined} applies. We claim that $LF$ is everywhere defined. This follows from Derived Categories, Lemma \ref{derived-lemma-find-existence-computes} with $\mathcal{P} \subset \Ob(\mathcal{D})$ the collection of $K$-flat complexes: (1) follows from Lemma \ref{lemma-K-flat-resolution} and to see (2) we have to show that for a quasi-isomorphism $\mathcal{K}_1^\bullet  \to \mathcal{K}_2^\bullet$ between K-flat complexes of $\mathcal{O}_Y$-modules the map $f^*\mathcal{K}_1^\bullet  \to f^*\mathcal{K}_2^\bullet$ is a quasi-isomorphism. To see this write this as $$ f^{-1}\mathcal{K}_1^\bullet \otimes_{f^{-1}\mathcal{O}_Y} \mathcal{O}_X \longrightarrow f^{-1}\mathcal{K}_2^\bullet \otimes_{f^{-1}\mathcal{O}_Y} \mathcal{O}_X $$ The functor $f^{-1}$ is exact, hence the map $f^{-1}\mathcal{K}_1^\bullet  \to f^{-1}\mathcal{K}_2^\bullet$ is a quasi-isomorphism. By Lemma \ref{lemma-pullback-K-flat} applied to the morphism $(X, f^{-1}\mathcal{O}_Y) \to (Y, \mathcal{O}_Y)$ the complexes $f^{-1}\mathcal{K}_1^\bullet$ and $f^{-1}\mathcal{K}_2^\bullet$ are K-flat complexes of $f^{-1}\mathcal{O}_Y$-modules. Hence Lemma \ref{lemma-derived-tor-quasi-isomorphism-other-side} guarantees that the displayed map is a quasi-isomorphism. Thus we obtain a derived functor $$ LF : D(\mathcal{O}_Y) = S^{-1}\mathcal{D} \longrightarrow \mathcal{D}' = D(\mathcal{O}_X) $$ see Derived Categories, Equation (\ref{derived-equation-everywhere}). Finally, Derived Categories, Lemma \ref{derived-lemma-find-existence-computes} also guarantees that $LF(\mathcal{K}^\bullet) = F(\mathcal{K}^\bullet) = f^*\mathcal{K}^\bullet$ when $\mathcal{K}^\bullet$ is K-flat, i.e., $Lf^* = LF$ is indeed computed in the way described above.
Let $E$ be an object of $D(\mathcal{O}_Z)$. By construction $Lg^*E$ is computed by choosing a K-flat complex $\mathcal{K}^\bullet$ representing $E$ on $Z$ and setting $Lg^*E = g^*\mathcal{K}^\bullet$. By Lemma \ref{lemma-pullback-K-flat} we see that $g^*\mathcal{K}^\bullet$ is K-flat on $Y$. Then $Lf^*Lg^*E$ is given by $f^*g^*\mathcal{K}^\bullet = (g \circ f)^*\mathcal{K}^\bullet$ which also represents $L(g \circ f)^*E$.
We may assume that $\mathcal{F}^\bullet$ and $\mathcal{G}^\bullet$ are K-flat complexes. In this case $\mathcal{F}^\bullet \otimes_{\mathcal{O}_Y}^{\mathbf{L}} \mathcal{G}^\bullet$ is just the total complex associated to the double complex $\mathcal{F}^\bullet \otimes_{\mathcal{O}_Y} \mathcal{G}^\bullet$. By Lemma \ref{lemma-tensor-product-K-flat} $\text{Tot}(\mathcal{F}^\bullet \otimes_{\mathcal{O}_Y} \mathcal{G}^\bullet)$ is K-flat also. Hence the isomorphism of the lemma comes from the isomorphism $$ \text{Tot}(f^*\mathcal{F}^\bullet \otimes_{\mathcal{O}_X} f^*\mathcal{G}^\bullet) \longrightarrow f^*\text{Tot}(\mathcal{F}^\bullet \otimes_{\mathcal{O}_Y} \mathcal{G}^\bullet) $$ whose constituents are the isomorphisms $f^*\mathcal{F}^p \otimes_{\mathcal{O}_X} f^*\mathcal{G}^q \to f^*(\mathcal{F}^p \otimes_{\mathcal{O}_Y} \mathcal{G}^q)$ of Modules, Lemma \ref{modules-lemma-tensor-product-pullback}.
We will use the existence of K-flat resolutions as in Lemma \ref{lemma-pullback-K-flat}. If we choose such resolutions $\mathcal{P}^\bullet \to \mathcal{K}^\bullet$ and $\mathcal{Q}^\bullet \to \mathcal{M}^\bullet$, then we see that $$ \xymatrix{ Lf^*\text{Tot}(\mathcal{P}^\bullet \otimes_{\mathcal{O}_Y} \mathcal{Q}^\bullet) \ar[r] \ar[d] & Lf^*\text{Tot}(\mathcal{K}^\bullet \otimes_{\mathcal{O}_Y} \mathcal{M}^\bullet) \ar[d] \\ f^*\text{Tot}(\mathcal{P}^\bullet \otimes_{\mathcal{O}_Y} \mathcal{Q}^\bullet) \ar[d] \ar[r] & f^*\text{Tot}(\mathcal{K}^\bullet \otimes_{\mathcal{O}_Y} \mathcal{M}^\bullet) \ar[d] \\ \text{Tot}(f^*\mathcal{P}^\bullet \otimes_{\mathcal{O}_X} f^*\mathcal{Q}^\bullet) \ar[r] & \text{Tot}(f^*\mathcal{K}^\bullet \otimes_{\mathcal{O}_X} f^*\mathcal{M}^\bullet) } $$ commutes. However, now the left hand side of the diagram is the left hand side of the diagram by our choice of $\mathcal{P}^\bullet$ and $\mathcal{Q}^\bullet$ and Lemma \ref{lemma-tensor-product-K-flat}.
By Lemma \ref{lemma-adjoint} we see that $Rg_* \circ Rf_*$ is adjoint to $Lf^* \circ Lg^*$. We have $Lf^* \circ Lg^* = L(g \circ f)^*$ by Lemma \ref{lemma-derived-pullback-composition} and hence by uniqueness of adjoint functors we have $Rg_* \circ Rf_* = R(g \circ f)_*$.
We will use the existence of K-flat resolutions and K-injective resolutions, see Lemma \ref{lemma-pullback-K-flat} and the discussion above. Choose a quasi-isomorphism $\mathcal{K}^\bullet \to \mathcal{I}^\bullet$ where $\mathcal{I}^\bullet$ is K-injective as a complex of $\mathcal{O}_X$-modules. Choose a quasi-isomorphism $\mathcal{Q}^\bullet \to f_*\mathcal{I}^\bullet$ where $\mathcal{Q}^\bullet$ is K-flat as a complex of $\mathcal{O}_Y$-modules. We can choose a K-flat complex of $\mathcal{O}_Y$-modules $\mathcal{P}^\bullet$ and a diagram of morphisms of complexes $$ \xymatrix{ \mathcal{P}^\bullet \ar[r] \ar[d] & f_*\mathcal{K}^\bullet \ar[d] \\ \mathcal{Q}^\bullet \ar[r] & f_*\mathcal{I}^\bullet } $$ commutative up to homotopy where the top horizontal arrow is a quasi-isomorphism. Namely, we can first choose such a diagram for some complex $\mathcal{P}^\bullet$ because the quasi-isomorphisms form a multiplicative system in the homotopy category of complexes and then we can replace $\mathcal{P}^\bullet$ by a K-flat complex. Taking pullbacks we obtain a diagram of morphisms of complexes $$ \xymatrix{ f^*\mathcal{P}^\bullet \ar[r] \ar[d] & f^*f_*\mathcal{K}^\bullet \ar[d] \ar[r] & \mathcal{K}^\bullet \ar[d] \\ f^*\mathcal{Q}^\bullet \ar[r] & f^*f_*\mathcal{I}^\bullet \ar[r] & \mathcal{I}^\bullet } $$ commutative up to homotopy. The outer rectangle witnesses the truth of the statement in the lemma.
(For a proof in case the complex is a bounded below complex of modules with finite filtrations, see the remark below.) Choose an map of filtered complexes $j : \mathcal{F}^\bullet \to \mathcal{J}^\bullet$ as in Injectives, Lemma \ref{injectives-lemma-K-injective-embedding-filtration}. The spectral sequence is the spectral sequence of Homology, Section \ref{homology-section-filtered-complex} associated to the filtered complex $$ \Gamma(X, \mathcal{J}^\bullet) \quad\text{with}\quad F^p\Gamma(X, \mathcal{J}^\bullet) = \Gamma(X, F^p\mathcal{J}^\bullet) $$ Since cohomology is computed by evaluating on K-injective representatives we see that the $E_1$ page is as stated in the lemma. The convergence and boundedness under the stated conditions follows from Homology, Lemma \ref{homology-lemma-ss-converges-trivial}.
The complex $f_*f^*\mathcal{F} \to  f_*f^*f_*f^*\mathcal{F} \to f_*f^*f_*f^*f_*f^*\mathcal{F} \to \ldots$ is the complex associated to the cosimplicial object with terms $f_*f^*\mathcal{F}, f_*f^*f_*f^*\mathcal{F}, f_*f^*f_*f^*f_*f^*\mathcal{F}, \ldots$ described above, see Simplicial, Section \ref{simplicial-section-dold-kan-cosimplicial}. The augmentation gives rise to the map $\mathcal{F} \to f_*f^*\mathcal{F}$ as indicated. For any abelian sheaf $\mathcal{H}$ on $X_{disc}$ the pushforward $f_*\mathcal{H}$ is flasque because $X_{disc}$ is a discrete space and the pushforward of a flasque sheaf is flasque. Hence the terms of the complex are flasque $\mathcal{O}_X$-modules. \medskip\noindent If $x \in X_{disc} = X$ is a point, then $(f^*\mathcal{G})_x = \mathcal{G}_x$ for any $\mathcal{O}_X$-module $\mathcal{G}$. Hence $f^*$ is an exact functor and a complex of $\mathcal{O}_X$-modules $\mathcal{G}_1 \to \mathcal{G}_2 \to \mathcal{G}_3$ is exact if and only if $f^*\mathcal{G}_1 \to f^*\mathcal{G}_2 \to f^*\mathcal{G}_3$ is exact (see Modules, Lemma \ref{modules-lemma-abelian}). The result mentioned in the introduction to this section proves the pullback by $f^*$ gives a homotopy equivalence from the constant cosimplicial object $f^*\mathcal{F}$ to the cosimplicial object with terms $f_*f^*\mathcal{F}, f_*f^*f_*f^*\mathcal{F}, f_*f^*f_*f^*f_*f^*\mathcal{F}, \ldots$. By Simplicial, Lemma \ref{simplicial-lemma-homotopy-equivalence-s-Q} we obtain that $$ f^*\mathcal{F}[0] \to \Big( f^*f_*f^*\mathcal{F} \to f^*f_*f^*f_*f^*\mathcal{F} \to f^*f_*f^*f_*f^*f_*f^*\mathcal{F} \to \ldots \Big) $$ is a homotopy equivalence. This immediately implies the two remaining statements of the lemma.
Let $\mathcal{A}$ be the category of complexes of $\mathcal{O}_X$-modules and let $\mathcal{B}$ be the category of complexes of $\mathcal{O}_X$-modules. Then we can apply the discussion above to the adjoint functors $f^*$ and $f_*$ between $\mathcal{A}$ and $\mathcal{B}$. Arguing exactly as in the proof of Lemma \ref{lemma-godement-resolution} we get a resolution $$ 0 \to \mathcal{F}^\bullet \to f_*f^*\mathcal{F}^\bullet \to f_*f^*f_*f^*\mathcal{F}^\bullet \to f_*f^*f_*f^*f_*f^*\mathcal{F}^\bullet \to \ldots $$ in the abelian category $\mathcal{A}$ such that each term of each $f_*f^*\ldots f_*f^*\mathcal{F}^\bullet$ is a flasque $\mathcal{O}_X$-module and such that for all $x \in X$ the map $$ \mathcal{F}^\bullet_x[0] \to \Big( (f_*f^*\mathcal{F}^\bullet)_x \to (f_*f^*f_*f^*\mathcal{F}^\bullet)_x \to (f_*f^*f_*f^*f_*f^*\mathcal{F}^\bullet)_x \to \ldots \Big) $$ is a homotopy equivalence in the category of complexes of complexes of $\mathcal{O}_{X, x}$-modules. Since a complex of complexes is the same thing as a double complex, we can consider the induced map $$ \mathcal{F}^\bullet \to \mathcal{G}^\bullet = \text{Tot}( f_*f^*\mathcal{F}^\bullet \to f_*f^*f_*f^*\mathcal{F}^\bullet \to f_*f^*f_*f^*f_*f^*\mathcal{F}^\bullet \to \ldots ) $$ Since the complex $\mathcal{F}^\bullet$ is bounded below, the same is true for $\mathcal{G}^\bullet$ and in fact each term of $\mathcal{G}^\bullet$ is a finite direct sum of terms of the complexes $f_*f^*\ldots f_*f^*\mathcal{F}^\bullet$ and hence is flasque. The final assertion of the lemma now follows from Homology, Lemma \ref{homology-lemma-homotopy-complex-complexes}. Since this in particular shows that $\mathcal{F}^\bullet \to \mathcal{G}^\bullet$ is a quasi-isomorphism, the proof is complete.
Choose quasi-isomorphisms of complexes $a : \mathcal{K}^\bullet \to \mathcal{K}_1^\bullet$ and $b : \mathcal{M}^\bullet \to \mathcal{M}_1^\bullet$ as in Lemma \ref{lemma-godement-resolution-bounded-below}. Since the maps $a$ and $b$ on stalks are homotopy equivalences we see that the induced map $$ \text{Tot}(\mathcal{K}^\bullet \otimes_{\mathcal{O}_X} \mathcal{M}^\bullet) \to \text{Tot}(\mathcal{K}_1^\bullet \otimes_{\mathcal{O}_X} \mathcal{M}_1^\bullet) $$ is a homotopy equivalence on stalks too (More on Algebra, Lemma \ref{more-algebra-lemma-derived-tor-homotopy}) and hence a quasi-isomorphism. Thus the targets $$ R\Gamma(X, \text{Tot}(\mathcal{K}^\bullet \otimes_{\mathcal{O}_X} \mathcal{M}^\bullet)) = R\Gamma(X, \text{Tot}(\mathcal{K}_1^\bullet \otimes_{\mathcal{O}_X} \mathcal{M}_1^\bullet)) $$ of the two diagrams are the same in $D(A)$. It follows that it suffices to prove the diagram commutes for $\mathcal{K}$ and $\mathcal{M}$ replaced by $\mathcal{K}_1$ and $\mathcal{M}_1$. This reduces us to the case discussed in the next paragraph. \medskip\noindent Assume $\mathcal{K}^\bullet$ and $\mathcal{M}^\bullet$ are bounded below complexes of flasque $\mathcal{O}_X$-modules and consider the diagram relating the cup product with the cup product (\ref{equation-needs-signs}) on {\v C}ech complexes. Then we can consider the commutative diagram $$ \xymatrix{ \Gamma(X, \mathcal{K}^\bullet) \otimes_A^\mathbf{L} \Gamma(X, \mathcal{M}^\bullet) \ar[d] \ar[r] & \text{Tot}(\check{\mathcal{C}}^\bullet(\mathcal{U}, \mathcal{K}^\bullet)) \otimes_A^\mathbf{L} \text{Tot}(\check{\mathcal{C}}^\bullet(\mathcal{U}, \mathcal{M}^\bullet)) \ar[d] \\ \text{Tot}(\Gamma(X, \mathcal{K}^\bullet) \otimes_A \Gamma(X, \mathcal{M}^\bullet)) \ar[d] \ar[r] & \text{Tot}( \text{Tot}(\check{\mathcal{C}}^\bullet(\mathcal{U}, \mathcal{K}^\bullet)) \otimes_A \text{Tot}(\check{\mathcal{C}}^\bullet(\mathcal{U}, \mathcal{M}^\bullet))) \ar[d]^{(\ref{equation-needs-signs})} \\ \Gamma(X, \text{Tot}(\mathcal{K}^\bullet \otimes_{\mathcal{O}_X} \mathcal{M}^\bullet)) \ar[r] & \text{Tot}( \check{\mathcal{C}}^\bullet({\mathcal U}, \text{Tot}(\mathcal{K}^\bullet \otimes_{\mathcal{O}_X} \mathcal{M}^\bullet) )) } $$ In this diagram the horizontal arrows are isomorphisms in $D(A)$ because for a bounded below complex of flasque modules such as $\mathcal{K}^\bullet$ we have $$ \Gamma(X, \mathcal{K}^\bullet) = \text{Tot}(\check{\mathcal{C}}^\bullet(\mathcal{U}, \mathcal{K}^\bullet)) = R\Gamma(X, \mathcal{K}^\bullet) $$ in $D(A)$. This follows from Lemma \ref{lemma-flasque-acyclic}, Derived Categories, Lemma \ref{derived-lemma-leray-acyclicity}, and Lemma \ref{lemma-cech-complex-complex-computes}. Hence the commutativity of the diagram of the lemma involving (\ref{equation-needs-signs}) follows from the already proven commutativity of Lemma \ref{lemma-cup-compatible-with-naive} where $f$ is the morphism to a point (see discussion following Lemma \ref{lemma-cup-compatible-with-naive}).
This is true because going around the diagram either way we obtain the map adjoint to the map \begin{align*} & L(g \circ f)^*\left(R(g \circ f)_*K \otimes_{\mathcal{O}_Z}^\mathbf{L} R(g \circ f)_*L\right) \\ & = L(g \circ f)^*R(g \circ f)_*K \otimes_{\mathcal{O}_X}^\mathbf{L} L(g \circ f)^*R(g \circ f)_*L) \\ & \to K \otimes_{\mathcal{O}_X}^\mathbf{L} L \end{align*} in $D(\mathcal{O}_X)$. To see this one uses that the composition of the counits like so $$ L(g \circ f)^*R(g \circ f)_* = Lf^* Lg^* Rg_* Rf_*  \to Lf^* Rf_* \to \text{id} $$ is the counit for $L(g \circ f)^*$ and $R(g \circ f)_*$. See Categories, Lemma \ref{categories-lemma-compose-counits}.
Follows from Derived Categories, Lemma \ref{derived-lemma-adjoint-preserve-K-injectives} and the fact that the restriction functor has the exact left adjoint $j_!$. For the construction of $j_!$ see Sheaves, Section \ref{sheaves-section-open-immersions} and for exactness see Modules, Lemma \ref{modules-lemma-j-shriek-exact}.
Let $\mathcal{I}^\bullet$ be a K-injective complex of $\mathcal{O}_X$-modules representing $K$. Then $$ H^q(U, K) = H^q(\Gamma(U, \mathcal{I}^\bullet)) = H^q(\Gamma(U, \mathcal{I}^\bullet|_U)) $$ by construction of cohomology. By Lemma \ref{lemma-restrict-K-injective-to-open} the complex $\mathcal{I}^\bullet|_U$ is a K-injective complex representing $K|_U$ and the lemma follows.
The equality $H^q(U, K) = H^q(U, K|_U)$ holds by Lemma \ref{lemma-unbounded-cohomology-of-open}. Choose a K-injective complex $\mathcal{I}^\bullet$ representing $K$. Then $$ H^q(U, K) = \frac{\Ker(\mathcal{I}^q(U) \to \mathcal{I}^{q + 1}(U))} {\Im(\mathcal{I}^{q - 1}(U) \to \mathcal{I}^q(U))}. $$ by our construction of cohomology. Since $H^q(K) = \Ker(\mathcal{I}^q \to \mathcal{I}^{q + 1})/ \Im(\mathcal{I}^{q - 1} \to \mathcal{I}^q)$ the result is clear.
Represent $E$ by a K-injective complex $\mathcal{I}^\bullet$ of $\mathcal{O}_X$-modules. Then $Rf_*(E) = f_*\mathcal{I}^\bullet$ and $Rg_*(E|_U) = g_*(\mathcal{I}^\bullet|_U)$ by Lemma \ref{lemma-restrict-K-injective-to-open}. Since it is clear that $(f_*\mathcal{F})|_V = g_*(\mathcal{F}|_U)$ for any sheaf $\mathcal{F}$ on $X$ the result follows.
Let $Z$ be the ringed space consisting of a singleton space with $\Gamma(Z, \mathcal{O}_Z) = \Gamma(Y, \mathcal{O}_Y)$. There is a canonical morphism $Y \to Z$ of ringed spaces inducing the identification on global sections of structure sheaves. Then $D(\mathcal{O}_Z) = D(\Gamma(Y, \mathcal{O}_Y))$. Hence the assertion $R\Gamma(Y, -) \circ Rf_* = R\Gamma(X, -)$ follows from Lemma \ref{lemma-derived-pushforward-composition} applied to $X \to Y \to Z$. \medskip\noindent The second (more general) statement follows from the first statement after applying Lemma \ref{lemma-restrict-direct-image-open}.
The map is constructed as follows. Choose a K-injective complex $\mathcal{I}^\bullet$ representing $K$. Choose a quasi-isomorpism $\mathcal{I}^\bullet \to \mathcal{J}^\bullet$ where $\mathcal{J}^\bullet$ is a K-injective complex of abelian groups. Then the map in (1) is given by $\Gamma(U, \mathcal{I}^\bullet) \to \Gamma(U, \mathcal{J}^\bullet)$ and the map in (2) is given by $f_*\mathcal{I}^\bullet \to f_*\mathcal{J}^\bullet$. To show that these maps are isomorphisms, it suffices to prove they induce isomorphisms on cohomology groups and cohomology sheaves. By Lemmas \ref{lemma-unbounded-cohomology-of-open} and \ref{lemma-unbounded-describe-higher-direct-images} it suffices to show that the map $$ H^0(X, K) \longrightarrow H^0(X, K_{ab}) $$ is an isomorphism. Observe that $$ H^0(X, K) = \Hom_{D(\mathcal{O}_X)}(\mathcal{O}_X, K) $$ and similarly for the other group. Choose any complex $\mathcal{K}^\bullet$ of $\mathcal{O}_X$-modules representing $K$. By construction of the derived category as a localization we have $$ \Hom_{D(\mathcal{O}_X)}(\mathcal{O}_X, K) = \colim_{s : \mathcal{F}^\bullet \to \mathcal{O}_X} \Hom_{K(\mathcal{O}_X)}(\mathcal{F}^\bullet, \mathcal{K}^\bullet) $$ where the colimit is over quasi-isomorphisms $s$ of complexes of $\mathcal{O}_X$-modules. Similarly, we have $$ \Hom_{D(\underline{\mathbf{Z}}_X)}(\underline{\mathbf{Z}}_X, K) = \colim_{s : \mathcal{G}^\bullet \to \underline{\mathbf{Z}}_X} \Hom_{K(\underline{\mathbf{Z}}_X)}(\mathcal{G}^\bullet, \mathcal{K}^\bullet) $$ Next, we observe that the quasi-isomorphisms $s : \mathcal{G}^\bullet \to \underline{\mathbf{Z}}_X$ with $\mathcal{G}^\bullet$ bounded above complex of flat $\underline{\mathbf{Z}}_X$-modules is cofinal in the system. (This follows from Modules, Lemma \ref{modules-lemma-module-quotient-flat} and Derived Categories, Lemma \ref{derived-lemma-subcategory-left-resolution}; see discussion in Section \ref{section-flat}.) Hence we can construct an inverse to the map $H^0(X, K) \longrightarrow H^0(X, K_{ab})$ by representing an element $\xi \in H^0(X, K_{ab})$ by a pair $$ (s : \mathcal{G}^\bullet \to \underline{\mathbf{Z}}_X, a : \mathcal{G}^\bullet \to \mathcal{K}^\bullet) $$ with $\mathcal{G}^\bullet$ a bounded above complex of flat $\underline{\mathbf{Z}}_X$-modules and sending this to $$ (\mathcal{G}^\bullet \otimes_{\underline{\mathbf{Z}}_X} \mathcal{O}_X \to \mathcal{O}_X, \mathcal{G}^\bullet  \otimes_{\underline{\mathbf{Z}}_X} \mathcal{O}_X \to \mathcal{K}^\bullet) $$ The only thing to note here is that the first arrow is a quasi-isomorphism by Lemmas \ref{lemma-derived-tor-quasi-isomorphism-other-side} and \ref{lemma-bounded-flat-K-flat}. We omit the detailed verification that this construction is indeed an inverse.
This is true because $$ \Hom_{K(\mathcal{O}_Y)}(\mathcal{F}^\bullet, f_*\mathcal{I}^\bullet) = \Hom_{K(\mathcal{O}_X)}(f^*\mathcal{F}^\bullet, \mathcal{I}^\bullet) $$ by Sheaves, Lemma \ref{sheaves-lemma-adjoint-pullback-pushforward-modules} and the fact that $f^*$ is exact as $f$ is assumed to be flat.
We have seen in Section \ref{section-properties-K-injective} that the restriction functors and the extension by zero functors are computed by just applying the functors to any complex. Let $\mathcal{E}^\bullet$ be a complex of $\mathcal{O}_X$-modules representing $E$. The distinguished triangle of the lemma is the distinguished triangle associated (by Derived Categories, Section \ref{derived-section-canonical-delta-functor} and especially Lemma \ref{derived-lemma-derived-canonical-delta-functor}) to the short exact sequence of complexes of $\mathcal{O}_X$-modules $$ 0 \to j_{U \cap V!}\mathcal{E}^\bullet|_{U \cap V} \to j_{U!}\mathcal{E}^\bullet|_U \oplus j_{V!}\mathcal{E}^\bullet|_V \to \mathcal{E}^\bullet \to 0 $$ To see this sequence is exact one checks on stalks using Sheaves, Lemma \ref{sheaves-lemma-j-shriek-modules} (computation omitted).
Choose a K-injective complex $\mathcal{I}^\bullet$ representing $E$ whose terms $\mathcal{I}^n$ are injective objects of $\textit{Mod}(\mathcal{O}_X)$, see Injectives, Theorem \ref{injectives-theorem-K-injective-embedding-grothendieck}. We have seen that $\mathcal{I}^\bullet|U$ is a K-injective complex as well (Lemma \ref{lemma-restrict-K-injective-to-open}). Hence $Rj_{U, *}E|_U$ is represented by $j_{U, *}\mathcal{I}^\bullet|_U$. Similarly for $V$ and $U \cap V$. Hence the distinguished triangle of the lemma is the distinguished triangle associated (by Derived Categories, Section \ref{derived-section-canonical-delta-functor} and especially Lemma \ref{derived-lemma-derived-canonical-delta-functor}) to the short exact sequence of complexes $$ 0 \to \mathcal{I}^\bullet \to j_{U, *}\mathcal{I}^\bullet|_U \oplus j_{V, *}\mathcal{I}^\bullet|_V \to j_{U \cap V, *}\mathcal{I}^\bullet|_{U \cap V} \to 0. $$ This sequence is exact because for any $W \subset X$ open and any $n$ the sequence $$ 0 \to \mathcal{I}^n(W) \to \mathcal{I}^n(W \cap U) \oplus \mathcal{I}^n(W \cap V) \to \mathcal{I}^n(W \cap U \cap V) \to 0 $$ is exact (see proof of Lemma \ref{lemma-mayer-vietoris}).
Use the distinguished triangle of Lemma \ref{lemma-exact-sequence-lower-shriek} to obtain a long exact sequence of $\Hom$'s (from Derived Categories, Lemma \ref{derived-lemma-representable-homological}) and use that $$ \Hom_{D(\mathcal{O}_X)}(j_{U!}E|_U, F) = \Hom_{D(\mathcal{O}_U)}(E|_U, F|_U) $$ by Lemma \ref{lemma-adjoint-lower-shriek-restrict}.