Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- void cvp(vector <pii> a){
- for (auto p: a){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- cout<<"\n";
- }
- set <pii> a,b;
- void del(pii p, set <pii> &s, set <pii> &q){//s - из к-рого удаляем; q - из к-рого p
- int L = 0, R = s.size(), M;
- while (L + 1 < R){
- M = (L + R) / 2;
- pii any = *next(s.begin(), M);
- if (any.first <= p.first){
- L = M;
- }
- else{
- R = M;
- }
- }
- pii any = *next(s.begin(), M);
- if (any.first == p.first){
- s.erase(p);
- q.erase(any);
- }
- }
- int f(int x){
- return (int)(log(x) / log(10)) + 1;
- }
- /*
- int first = *next(myset.begin(),0);
- int third = *next(myset.begin(),2);
- */
- bool sh=1;
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- int t=1;
- if (!sh) cin>>t;
- for (int go = 0; go < t; ++go){
- int n; cin>>n;
- int ans=0;
- a.clear();
- b.clear();
- for (int i = 0; i < n; ++i){
- int x; cin>>x; a.insert({x,i});
- }
- for (int i = 0; i < n; ++i){
- int x; cin>>x; b.insert({x,i});
- }
- for (auto i = a.begin(); i != a.end(); ++i){
- del(*i, b, a);
- }
- for (auto i = a.begin(); i != a.end(); ++i){
- int asz = a.size(), bsz = b.size();
- pii p = *i;
- pii k = {f(p.first), p.second};
- del(k, b, a);
- if (a.size() < asz){
- a.erase(p);
- a.insert(k);
- ans++;
- }
- }
- for (auto i = b.begin(); i != b.end(); ++i){
- int asz = a.size(), bsz = b.size();
- pii p = *i;
- pii k = {f(p.first), p.second};
- del(k, a, b);
- if (a.size() < asz){
- b.erase(p);
- b.insert(k);
- ans++;
- }
- }
- ans += 2 * a.size();
- for (auto i = a.begin(); i != a.end(); ++i){
- pii p = *i;
- pii k = {f(p.first), p.second};
- a.erase(p);
- a.insert(k);
- }
- for (auto i = b.begin(); i != b.end(); ++i){
- pii p = *i;
- pii k = {f(p.first), p.second};
- b.erase(p);
- b.insert(k);
- del(k, a, b);
- }
- ans += 2 * a.size();
- cout<<ans<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement