Advertisement
Korotkodul

CF C 09.09

Sep 2nd, 2022 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int,int>
  11. #define vec vector
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v){
  17.     for (auto x: v) cout<<x<<' ';
  18.     cout<<"\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v){
  22.     for (auto x: v) cout<<x<<' ';
  23.     cout<<"\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v){
  28.     for (auto x: v) cv(x);
  29.     cout<<"\n";
  30. }
  31.  
  32. void cvb(vector <bool> v){
  33.     for (bool x: v) cout<<x<<' ';
  34.     cout<<"\n";
  35. }
  36.  
  37. void cvs(vector <string>  v){
  38.     for (auto a: v){
  39.         cout<<a<<"\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a){
  44.     for (auto p: a){
  45.         cout<<p.first<<' '<<p.second<<"\n";
  46.     }
  47.     cout<<"\n";
  48. }
  49.  
  50. set <pii> a,b;
  51. void del(pii p, set <pii> &s, set <pii> &q){//s - из к-рого удаляем; q - из к-рого p
  52.     int L = 0, R = s.size(), M;
  53.     while (L + 1 < R){
  54.         M = (L + R) / 2;
  55.         pii any = *next(s.begin(), M);
  56.         if (any.first <= p.first){
  57.             L = M;
  58.         }
  59.         else{
  60.             R = M;
  61.         }
  62.     }
  63.     pii any = *next(s.begin(), M);
  64.     if (any.first == p.first){
  65.         s.erase(p);
  66.         q.erase(any);
  67.     }
  68. }
  69.  
  70. int f(int x){
  71.     return (int)(log(x) / log(10)) + 1;
  72. }
  73.  
  74. /*
  75. int first = *next(myset.begin(),0);
  76. int third = *next(myset.begin(),2);
  77. */
  78. bool sh=1;
  79. int main()
  80. {
  81.     ios::sync_with_stdio(0);
  82.     cin.tie(0);
  83.     cout.tie(0);
  84.     int t=1;
  85.     if (!sh) cin>>t;
  86.     for (int go = 0; go < t; ++go){
  87.         int n; cin>>n;
  88.         int ans=0;
  89.         a.clear();
  90.         b.clear();
  91.         for (int i = 0; i < n; ++i){
  92.             int x; cin>>x; a.insert({x,i});
  93.         }
  94.         for (int i = 0; i < n; ++i){
  95.             int x; cin>>x; b.insert({x,i});
  96.         }
  97.         for (auto i = a.begin(); i != a.end(); ++i){
  98.             del(*i, b, a);
  99.         }
  100.  
  101.         for (auto i = a.begin(); i != a.end(); ++i){
  102.             int asz = a.size(), bsz = b.size();
  103.             pii p = *i;
  104.             pii k = {f(p.first), p.second};
  105.  
  106.             del(k, b, a);
  107.             if (a.size() < asz){
  108.                 a.erase(p);
  109.                 a.insert(k);
  110.                 ans++;
  111.             }
  112.         }
  113.  
  114.         for (auto i = b.begin(); i != b.end(); ++i){
  115.             int asz = a.size(), bsz = b.size();
  116.             pii p = *i;
  117.             pii k = {f(p.first), p.second};
  118.  
  119.             del(k, a, b);
  120.             if (a.size() < asz){
  121.                 b.erase(p);
  122.                 b.insert(k);
  123.                 ans++;
  124.             }
  125.         }
  126.  
  127.         ans += 2 * a.size();
  128.  
  129.         for (auto i = a.begin(); i != a.end(); ++i){
  130.             pii p = *i;
  131.             pii k = {f(p.first), p.second};
  132.             a.erase(p);
  133.             a.insert(k);
  134.         }
  135.         for (auto i = b.begin(); i != b.end(); ++i){
  136.             pii p = *i;
  137.             pii k = {f(p.first), p.second};
  138.             b.erase(p);
  139.             b.insert(k);
  140.             del(k, a, b);
  141.         }
  142.         ans += 2 * a.size();
  143.         cout<<ans<<"\n";
  144.     }
  145. }
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement