2007年国内予選B(Analyzing Login/Logout Records)(2007/07/30(月) 00:44:10)
2007年国内予選B問題のAnalyzing Login/Logout Records(ログイン/ログアウト記録の解析)をやってみました。
解法
3600のboolean配列を用意すればよい感じ?
ソース
(目標10分以内)
#include <iostream> using namespace std; typedef struct LOG{ bool t[3601]; int l[1001]; }LOG; int main(){ int N, M; LOG *L = new LOG[10001]; while(cin >> N >> M, (N || M)){ for(int i = 0; i < 10001; i++){ for(int j = 0; j < 3601; j++){ L[i].t[j] = false; } } int r; cin >> r; for(int i = 0; i < r; i++){ int t, m, n, s; cin >> t >> n >> m >> s; //log in if(s == 1){ L[m].l[n] = t; } //log out else{ for(int j = L[m].l[n]; j < t; j++){ L[m].t[j] = true; } } } int q; cin >> q; for(int i = 0; i < q; i++){ int ts, te, m; cin >> ts >> te >> m; int count = 0; for(int j = ts; j < te; j++){ if(L[m].t[j])count++; } cout << count << endl; } } return 0; }