Data structure for interval subset queries
Let $F(I) = |\{s \in S : s \subseteq I\}|$ where $I$ is an interval.
If $[a, b]$ is our query interval, we can make the following partition where $R$ is our desired result:
$$R =n -F((-\infty, b)) - F((a, \infty)) + F((a, b))$$
The first two queries can be answered simply using a sorted data structure of respectively endpoints and startpoints.
The last query is the dual of this problem, which has an answer here on this site.