Distinction between "types of heat" in thermal efficiency The definition of thermal efficiency I see in several sources is "total work" divided by "heat input".
Wikipedia, for example, says: "For a heat engine, thermal efficiency is the ratio of the net work output to the heat input".
I don't understand this definition. Net work is a perfectly valid concept, always given by $\oint pdV$. For a Carnot cycle, heat presents no problem, because the adiabatic processes involve no heat, while the isothermic processes are easily identified as consuming heat or producing heat.
However, for a general cycle this distinction between "heat input" and "heat output" is not clear. Just imagine a generic cycle in a $p-V$ diagram. How I am supposed to know which bits of the cycle are "heat input" and which are "heat output"?
 A: The way to track this in complete generality, for a reversible process, is to track the system entropy. If the entropy went up, then heat came in. If the system entropy fell then heat went out.
If you want a method that does not involve any mention of the concept of entropy, then proceed as follows. For a given change first calculate the work done on the system $W$, and then find out (from an energy equation or from previously acquired data) the change $\Delta U$ in the internal energy of the system. If $\Delta U > W$ then heat flowed in. If $\Delta U < W$ then heat flowed out.
A: First of all, $\oint pdV$ is the net work only if $p$ equals the external pressure. If the process is not reversible then the internal pressure is not equal the external pressure. So assume that the process is reversible.
In that case, in an arbitrary reversible cycle during which the transported entropy between the system (engine) and its surroundings at temperature $T$ is denoted by $dS$ then $\oint pdV = \oint TdS$. If $dS>0$ then we call the entropy absorbed by the engine and if $dS<0$ it is expelled (rejected). You may call $Q_{abs}=\oint_{dS>0} TdS$, and $Q_{rej}=-\oint_{dS<0} TdS$ and define the cycle efficiency as the ratio
$$\eta = \frac{\oint pdV}{\oint_{dS>0} TdS}=1+\frac{\oint_{dS<0} TdS}{\oint_{dS>0} TdS}$$
For a Carnot cycle, there are two isothermal stages $\int TdS = T_h (S_2-S_1)$ and $\int TdS = T_\ell (S_4-S_3)$ where $1,2,3,4$ refer to the stages at which the cycle changes from isothermal (1-2) to adiabatic (2-3) to isothermal (3-4) - adiabatic (4-1). Therefore $S_2=S_3$ and $S_1=S_4$, and $\Delta S= S_2-S_1=S_3-S_4$ will be the absorbed and rejected entropy resulting $\oint pdV = \oint TdS = (T_h-T_{\ell})\Delta S$, and thus $\eta = 1-\frac{T_{\ell}}{T_h}$
A: 
Just imagine a generic cycle in a $p-V$ diagram. How I am supposed to
know which bits of the cycle are "heat input" and which are "heat
output"?

Based on your comments to @Chemomechanics, I understand you are referring to reversible cycles. As such, in general any bit of a heat engine gas cycle involving an increase in volume involves a heat input, with the exception of an adiabatic expansion. Also, any constant volume increase in pressure is a heat input.
To check for an adiabatic expansion, you need to have information on the beginning and ending equilibrium states for each piece of the cycle. Then, for an ideal gas, the expansion is reversible adiabatic if it obeys the following between equilibrium states 1 and 2.
$$P_{1}V_{1}^{\gamma}=P_{2}V_{2}^{\gamma}$$
where $$\gamma = \frac{c_{p}}{c_v}$$
Below is a generic reversible cycle in a P-V diagram cycle showing heat inputs and outputs.  Note the cycle moves clockwise. It assumes no adiabatic expansions. Being reversible, the pressure on the diagram represents both the external pressure and the internal equilibrium pressure. For each point on the cycle the ideal gas equation applies (i.e.,$Pv=nRT$). The efficiency of the cycle is the net work done (area enclosed by the cycle) divided by the sum of the heat inputs, which is also referred to as the "gross heat input"
Hope this helps.

A: The model engine is the Carnot cycle: it receives heat $Q_H = T_H (S_2-S_1)$ at the higher temperature $T_H$, where $S_2>S_1$ are the entropies at the end of each isentropic part. On the $TS$ graph the Carnot is rectangle. Arbitrary cycles can be represented by a number of Carnot cycles operating in tandem.

The net heat to this cycle is the sum of the $dQ_H$ terms. The heat exchanged at any point of that cycle is $T dS$; if $dS>0$, this heat enters the system, otherwise it exists. Therefore, the net amount of heat entering the cycle is the integral of $T dS$ under the condition $dS>0$. This is the integral in the answer by hyportnex.
