-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path32.cpp
82 lines (68 loc) · 1.98 KB
/
32.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// O(t*m) with t is number of test case and m is the number of cars
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <sstream>
#include <iterator>
#include <set>
#include <stack>
#include <numeric>
#include <regex>
#include <queue>
#include <iomanip>
using namespace std;
#define FILE_IO {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(NULL), cout.tie(NULL)
#define id first
#define vl second
int main() {
FAST_IO;
// FILE_IO;
int N, n, t, m, x, fb, ft, noc, res[10010]; cin >> N;
string b;
bool isMove;
while (N--) {
cin >> n >> t >> m;
queue<pair<int, int>> q[2];
for (int i = 0; i < m; ++i) {
cin >> x >> b;
q[(b == "right")].push({i, x});
}
ft = 0, fb = 0;
while (q[0].empty() + q[1].empty() != 2) {
isMove = false;
noc = 0;
while (!q[fb].empty() && noc++ < n && q[fb].front().vl <= ft) {
res[q[fb].front().id] = ft + t;
q[fb].pop();
isMove = true;
}
if (isMove) {
ft += t;
fb = 1 - fb;
continue;
}
if (q[0].empty() + q[1].empty() == 0) {
if (q[fb].front().vl <= q[1 - fb].front().vl) {
ft = max(ft, q[fb].front().vl);
} else {
ft = max(ft, q[1 - fb].front().vl) + t;
fb = 1 - fb;
}
} else {
if (!q[fb].empty()) {
ft = max(ft, q[fb].front().vl);
} else if (!q[1 - fb].empty()) {
ft = max(ft, q[1 - fb].front().vl) + t;
fb = 1 - fb;
}
}
}
for (int i = 0; i < m; ++i) {
cout << res[i] << endl;
}
if (N) cout << endl;
}
return 0;
}