Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #ifdef ERFANUL007
- #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
- template < typename Arg1 >
- void __f(const char* name, Arg1&& arg1){
- cout << name << " = " << arg1 << std::endl;
- }
- template < typename Arg1, typename... Args>
- void __f(const char* names, Arg1&& arg1, Args&&... args){
- const char* comma = strchr(names, ',');
- cout.write(names, comma - names) << " = " << arg1 <<" | ";
- __f(comma+1, args...);
- }
- #else
- #define debug(...)
- #endif
- int main(){
- #ifdef ERFANUL007
- clock_t tStart = clock();
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int t, cs=0;
- cin >> t;
- //debug(t);
- while(t--){
- ll l;
- int n, m;
- cin >> n >> l >> m;
- //debug(l, m);
- vector< pair< ll, int > > left, right;
- ll ans[m];
- for(int i=0; i < m; i++){
- ll x;
- string s;
- cin >> x >> s;
- //debug(x, s);
- if(s == "left") left.push_back(make_pair(x, i));
- else right.push_back(make_pair(x, i));
- ans[i] = 0;
- }
- int i=0, j=0;
- ll cur_time = 0;
- bool bank_left = true;
- while(i < left.size() || j < right.size()){
- if(bank_left){
- int niche = 0;
- while(i < left.size() && left[i].first <= cur_time && niche < n){
- ans[left[i++].second] = cur_time + l;
- niche++;
- }
- if(niche){
- cur_time += l;
- bank_left = false;
- continue;
- }
- if(i < left.size() && j < right.size()){
- if(left[i].first <= right[j].first){
- cur_time = max(cur_time, left[i].first);
- }
- else{
- cur_time = max(cur_time + l, right[j].first + l);
- bank_left = false;
- }
- }
- else if(i < left.size()){
- cur_time = max(cur_time, left[i].first);
- }
- else if(j < right.size()){
- cur_time = max(cur_time + l, right[j].first + l);
- bank_left = false;
- }
- }
- else{
- int niche = 0;
- while(j < right.size() && right[j].first <= cur_time && niche < n){
- ans[right[j++].second] = cur_time + l;
- niche++;
- }
- if(niche){
- cur_time += l;
- bank_left = true;
- continue;
- }
- if(i < left.size() && j < right.size()){
- if(left[i].first < right[j].first){
- cur_time = max(cur_time + l, left[i].first + l);
- bank_left = true;
- }
- else{
- cur_time = max(cur_time, right[j].first);
- }
- }
- else if(i < left.size()){
- cur_time = max(cur_time+l, left[i].first + l);
- bank_left = true;
- }
- else if(j < right.size()){
- cur_time = max(cur_time, right[j].first);
- }
- }
- }
- if(cs) cout << '\n';
- cs++;
- for(int i=0; i<m; i++){
- cout << ans[i] << '\n';
- }
- }
- #ifdef ERFANUL007
- fprintf(stderr, ">>> Runtime : %.9f\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement