fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. #define printl(v) for (auto it : v) printf("%lld ", it); puts("");
  6.  
  7. int main(){
  8. ios::sync_with_stdio(false);
  9. cin.tie(0);
  10. ll L, N, M;
  11. cin >> L >> N >> M;
  12. ll N_U =0, N_R=0;
  13. vector<ll> A_U;
  14. for(ll i=0;i<N;i++){
  15. char type;
  16. ll C;
  17. cin >> type >> C;
  18. if(type == 'U'){
  19. N_U++;
  20. A_U.push_back(C);
  21. }
  22. else{
  23. N_R++;
  24. }
  25. }
  26. ll M_U =0, M_L=0;
  27. vector<ll> B_U;
  28. for(ll i=0;i<M;i++){
  29. char type;
  30. ll C;
  31. cin >> type >> C;
  32. if(type == 'U'){
  33. M_U++;
  34. B_U.push_back(C);
  35. }
  36. else{
  37. M_L++;
  38. }
  39. }
  40. // Sort A_U and B_U
  41. sort(A_U.begin(), A_U.end());
  42. sort(B_U.begin(), B_U.end());
  43. for(auto&it:B_U)
  44. cout<<it<<" ";
  45. cout<<endl;
  46. // Count K: number of C in both A_U and B_U
  47. ll K=0;
  48. size_t a=0, b_idx=0;
  49. while(a < A_U.size() && b_idx < B_U.size()){
  50. if(A_U[a] == B_U[b_idx]){
  51. K++;
  52. a++;
  53. b_idx++;
  54. }
  55. else if(A_U[a] < B_U[b_idx]){
  56. a++;
  57. }
  58. else{
  59. b_idx++;
  60. }
  61. }
  62. // Compute I
  63. ll I = N_U * M_L + N_R * M_U + N_R * M_L - K;
  64. // Compute boundary_segments
  65. ll boundary_segments = M_L + N_U + M_U + N_R + 4;
  66. // Compute beam_segments
  67. ll beam_segments = N_U * (M_L +1) + N_R * (M_L + M_U +1) + M_U * (N_R +1) + M_L * (N_U + N_R +1);
  68. // Compute E
  69. ll E = boundary_segments + beam_segments;
  70. // Compute V
  71. ll V = 4 + N + M + I;
  72. // Compute F
  73. ll F;
  74. //cout<<E<<" "<<V<<endl;
  75. if(N >0 && M >0){
  76. F = E - V + 2;
  77. }
  78. else{
  79. F = E - V + 1;
  80. }
  81. cout << F;
  82. }
  83.  
Success #stdin #stdout 0s 5300KB
stdin
30 3 2
U 10
U 25
R 10
L 15
U 20
stdout
20 
11