Advertisement
7oSkaaa

L - Median

Aug 1st, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define cin(vec) for(auto& i : vec) cin >> i
  5. #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  6. #define cout(vec) for(auto& i : vec) cout << i << " "; cout << "\n";
  7. #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
  8. #define cout_map(mp) for(auto& [f, s] : mp) cout << f << "  " << s << "\n";
  9. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  10. #define fixed(n) fixed << setprecision(n)
  11. #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  12. #define fill(vec, value) memset(vec, value, sizeof(vec));
  13. #define Num_of_Digits(n) ((int)log10(n)+1)
  14. #define mod_combine(a, b, m) (((a % m) * (b % m)) % m)
  15. #define all(vec) vec.begin(),vec.end()
  16. #define rall(vec) vec.rbegin(),vec.rend()
  17. #define sz(x) int(x.size())
  18. #define TC int t; cin >> t;   while(t--)
  19. #define fi first
  20. #define se second
  21. #define Pair pair < int, int >
  22. #define ll long long
  23. #define ull unsigned long long
  24. #define Mod  1'000'000'007
  25. #define OO 2'000'000'000
  26. #define EPS 1e-9
  27. #define PI acos(-1)
  28.  
  29. void AhMeD_HoSSaM(){
  30.   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  31.   #ifndef ONLINE_JUDGE
  32.     //freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  33.   #endif
  34.   freopen("median.in", "r", stdin);
  35. }
  36.  
  37. char median(string& s, int l1, int r1, int l2, int r2){
  38.   string new_string = s.substr(l1, r1 - l1 + 1) + s.substr(l2, r2 - l2 + 1);
  39.   sort(all(new_string));
  40.   return new_string[sz(new_string) / 2];
  41. }
  42.  
  43. int main(){
  44.   AhMeD_HoSSaM();
  45.   TC {
  46.     string s;
  47.     int query, type;
  48.     cin >> s >> query;
  49.     while(query-- && cin >> type){
  50.       if(type == 0){
  51.         int idx;
  52.         char change;
  53.         cin >> idx >> change;
  54.         s[idx] = change;
  55.       }else {
  56.         int l1, r1, l2, r2;
  57.         cin >> l1 >> r1 >> l2 >> r2;
  58.         cout << median(s, l1, r1, l2, r2) << "\n";
  59.       }
  60.     }
  61.   }
  62.   Time
  63.   return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement