水题~

View Code
1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 #include <vector>
5 #include <map>
6
7  using namespace std;
8
9  const int maxL = 32;
10 const int maxP = 10240;
11 const int maxQ = 51200;
12
13 struct TT
14 {
15 int Y, M, D;
16
17 int h, m, s;
18 };
19
20 struct PP
21 {
22 char name[maxL];
23 int prio;
24 TT get;
25 };
26
27 PP p[maxP];
28
29 vector<int> pmod[maxP];
30
31 struct OO
32 {
33 TT t;
34 int p, k, l;
35 };
36
37 OO o[maxQ];
38
39 int ocnt;
40
41 struct LL
42 {
43 TT last;
44 int p;
45 };
46
47 LL line[maxQ];
48
49 struct OUT
50 {
51 TT t;
52 int p;
53 int l;
54 };
55
56 OUT out[maxQ];
57
58 int outcnt;
59
60 int np;
61 int mcnt;
62 int modify[maxQ];
63
64 bool ac[maxQ];
65
66 map<int,int> line_id;
67
68 bool cmp(const TT & a,const TT & b)
69 {
70 if (a.Y != b.Y) return a.Y < b.Y;
71 if (a.M != b.M) return a.M < b.M;
72 if (a.D != b.D) return a.D < b.D;
73 if (a.h != b.h) return a.h < b.h;
74 if (a.m != b.m) return a.m < b.m;
75 return a.s < b.s;
76 }
77
78 bool cmpall(const OO & a,const OO & b)
79 {
80 return cmp(a.t,b.t);
81 }
82
83 bool outcmp(const OUT & a,const OUT & b)
84 {
85 return a.l < b.l;
86 }
87
88 int main()
89 {
90 int onum;
91 int lnum;
92 char opp[maxL];
93
94 while (scanf("%d",&np) != EOF)
95 {
96 if (np == 0) break;
97
98 ocnt = 0;
99 mcnt = 0;
100 line_id.clear();
101 for (int i = 0;i < np;i++)
102 pmod[i].clear();
103
104 for (int i = 0;i < np;i++)
105 {
106 scanf("%s %d %d",p[i].name,&p[i].prio,&onum);
107
108 for (int j = 0;j < onum;j++)
109 {
110 scanf(" \[%4d/%2d/%2d %2d:%2d:%2d] %s",&o[ocnt].t.Y,&o[ocnt].t.M,&o[ocnt].t.D,&o[ocnt].t.h,&o[ocnt].t.m,&o[ocnt].t.s,opp);
111
112 if (strcmp(opp,"SYNC") == 0) o[ocnt].k = 0;
113 else if (strcmp(opp,"MODIFY") == 0)
114 {
115 scanf("%d",&lnum);
116 if (line_id.count(lnum) == 0)
117 {
118 modify[mcnt] = lnum;
119 line_id[lnum] = mcnt++;
120 }
121 o[ocnt].k = 1;
122 o[ocnt].l = line_id[lnum];
123 }
124 else
125 o[ocnt].k = 2;
126 o[ocnt++].p = i;
127 }
128 }
129
130 sort(o,o + ocnt,cmpall);
131
132 memset(ac,false,sizeof(ac));
133 for (int i = 0;i < ocnt;i++)
134 {
135 int kind = o[i].k;
136 if (kind == 0) p[o[i].p].get = o[i].t;
137 else if (kind == 1) pmod[o[i].p].push_back(o[i].l);
138 else
139 {
140 int size = pmod[o[i].p].size();
141 for (int j = 0;j < size;j++)
142 if (!ac[pmod[o[i].p][j]])
143 {
144 line[pmod[o[i].p][j]].last = o[i].t;
145 line[pmod[o[i].p][j]].p = o[i].p;
146 ac[pmod[o[i].p][j]] = true;
147 }
148 else if (cmp(line[pmod[o[i].p][j]].last,p[o[i].p].get))
149 {
150 line[pmod[o[i].p][j]].last = o[i].t;
151 line[pmod[o[i].p][j]].p = o[i].p;
152 }
153 else if (p[o[i].p].prio > p[line[pmod[o[i].p][j]].p].prio)
154 {
155 line[pmod[o[i].p][j]].last = o[i].t;
156 line[pmod[o[i].p][j]].p = o[i].p;
157 }
158 pmod[o[i].p].clear();
159 p[o[i].p].get = o[i].t;
160 }
161 }
162
163 outcnt = 0;
164 for (int i = 0;i < mcnt;i++)
165 if (ac[i])
166 {
167 out[outcnt].t = line[i].last;
168 out[outcnt].p = line[i].p;
169 out[outcnt++].l = modify[i];
170 }
171
172 sort(out,out + outcnt,outcmp);
173
174 for (int i = 0;i < outcnt;i++)
175 printf("%d [%04d/%02d/%02d %02d:%02d:%02d] BY %s\n",out[i].l,out[i].t.Y,out[i].t.M,out[i].t.D,out[i].t.h,out[i].t.m,out[i].t.s,p[out[i].p].name);
176 printf("END\n");
177 }
178 return 0;
179 }