|
| 1 | +#include<bits/stdc++.h> |
| 2 | + |
| 3 | +using namespace std; |
| 4 | + |
| 5 | +#define ms(x,v) memset(x,(v), sizeof(x)) |
| 6 | +#define msn(x,v,n) memset(x,(v),sizeof(x[0]) * n) |
| 7 | +#define INF 0x3f3f3f3f |
| 8 | + |
| 9 | +typedef long long LL; |
| 10 | +typedef pair<int,int> PII; |
| 11 | + |
| 12 | +const int MAXN = 2e5 +10; |
| 13 | + |
| 14 | +struct Node{ |
| 15 | + int cur,dir,ans; |
| 16 | + vector<int> ids; |
| 17 | +}; |
| 18 | + |
| 19 | + |
| 20 | +void solve(){ |
| 21 | + int N,G,M; |
| 22 | + cin >> N >> G>>M; |
| 23 | + vector<vector<int> > guests(2*N); |
| 24 | + |
| 25 | + for(int i=0 ; i< G; ++i){ |
| 26 | + int s; |
| 27 | + char x; |
| 28 | + cin >> s>>x; |
| 29 | + s--;// map to [0,N) |
| 30 | + int dir = x == 'C' ? 1 : -1; |
| 31 | + s = (s + dir * (M%N) +N) % N; |
| 32 | + int idx = (s<<1) + (dir==1); |
| 33 | + guests[idx].push_back(i); |
| 34 | + } |
| 35 | + |
| 36 | + vector<Node> gg; |
| 37 | + for(int i=0 ; i<guests.size() ; ++i){ |
| 38 | + if(guests[i].empty())continue; |
| 39 | + Node tmp = { |
| 40 | + i>>1, |
| 41 | + i&1 ? -1 : 1, // anti-dir |
| 42 | + 0, |
| 43 | + guests[i], |
| 44 | + }; |
| 45 | + gg.push_back(tmp); |
| 46 | + } |
| 47 | + vector<int> timep(N,-1); |
| 48 | + int not_vis = N; |
| 49 | + if(M > N) M = N; |
| 50 | + for(int time = M ; time >= 0 && not_vis>0 ; --time) |
| 51 | + { |
| 52 | + for(int i=0 ; i< gg.size() ; ++i){ |
| 53 | + int & cur = gg[i].cur; |
| 54 | + if(timep[cur]<time){ |
| 55 | + not_vis--; |
| 56 | + timep[cur] = time; |
| 57 | + }//first access |
| 58 | + if(timep[cur] <=time){ |
| 59 | + gg[i].ans ++; |
| 60 | + } |
| 61 | + gg[i].cur= (cur + gg[i].dir + N) % N; |
| 62 | + } |
| 63 | + } |
| 64 | + vector<int> ans(G); |
| 65 | + for(auto e: gg){ |
| 66 | + for(auto id : e.ids) |
| 67 | + ans[id] = e.ans; |
| 68 | + } |
| 69 | + for(int i=0 ; i < ans.size(); ++i) |
| 70 | + cout << " " << ans[i]; |
| 71 | + |
| 72 | +} |
| 73 | + |
| 74 | +int main(int argc, char const *argv[]) |
| 75 | +{ |
| 76 | + |
| 77 | + ios :: sync_with_stdio(0); |
| 78 | + cin.tie(0); |
| 79 | + // cout.tie(0); |
| 80 | + std::cout.precision(8); |
| 81 | + std::cout.setf( std::ios::fixed, std:: ios::floatfield ); |
| 82 | + int T; |
| 83 | + cin >> T; |
| 84 | + |
| 85 | + for(int kase =1; kase <= T ; ++kase) |
| 86 | + { |
| 87 | + cout << "Case #"<<kase << ":"; |
| 88 | + |
| 89 | + solve(); |
| 90 | + cout << '\n'; |
| 91 | + } |
| 92 | + |
| 93 | + return 0; |
| 94 | +} |
0 commit comments