とんちゃんといっしょ

Cloudに関する技術とか日常とかについて書いたり書かなかったり

ログイン/ログアウト記録の解析

Problem B
http://icpc.logos.ic.i.u-tokyo.ac.jp/icpc2007/contest/B_ja.html

import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class B {
	Scanner sc = new Scanner(System.in);
	Student student[];
	
	class Student{
		List<Integer> li = new LinkedList<Integer>();
		List<Integer> lo = new LinkedList<Integer>();
		int time[] = new int[1261];
		
		void update(){
			for(int i = 0; i < li.size(); i++){
				for(int j = li.get(i)+1; j <= lo.get(i); j++){
					time[j] = 1;
				}
			}
		}
	}
	
	B(){
		for(;;){
			int N, M;
			N = sc.nextInt();
			M = sc.nextInt();
			if(N==0 && M==0) break;
			
			student = new Student[M]; 
			for(int i = 0; i < M; i++){
				student[i] = new Student();
			}
			
			int r = sc.nextInt();
			for(int i = 0; i < r; i++){
				int t, n, m, s;				
				t = sc.nextInt();
				n = sc.nextInt();
				m = sc.nextInt();
				s = sc.nextInt();
				
				if(s == 1){
					student[m-1].li.add(t);
				}else{
					student[m-1].lo.add(t);
				}
			}
			
			for(int i = 0; i < M; i++){
				student[i].update();
			}
			
			int q = sc.nextInt();
			for(int i = 0; i < q; i++){
				int ts, te, m;
				ts = sc.nextInt();
				te = sc.nextInt();
				m = sc.nextInt();
				
				int count = 0;
				for(int j = ts+1; j <= te; j++){
					if(student[m-1].time[j] == 1){
						count++;
					}
				}
				System.out.println(count);
			}
		}	
		
	}
	
	public static void main(String[] args) {
		new B();
	}
}