title: Data structure for storing ranges of data with timeline
body: <p>I need to store the activity log data for users in my application. It includes the the time when the user started doing an activity. For e.g., at 1 PM, the started 'Activity A'. At 2 PM, the user started 'Activity B'. At 3 PM, the user started 'Avtivity A'. From these logs, I should later be able to query information like</p>
  
  <ol>
  <li>How long was the user doing Activity A between 12 AM to 8 PM?</li>
  <li>How many times did the user switch activities etc.</li>
  </ol>
  
  <p>Can anyone suggest what would be a good in-memory data structure to store such information? </p>
  
  <p>Edit: There could be thousands of logs. A user can't do multiple activities at the same time.</p>