Advertisement
Guest User

pC

a guest
Nov 12th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | None | 0 0
  1. // #include <boost/multiprecision/cpp_int.hpp>
  2. // using namespace boost::multiprecision;
  3.  
  4. // #include <bits/extc++.h>
  5. // #include <ext/pb_ds/assoc_container.hpp>
  6. // #include <ext/pb_ds/tree_policy.hpp> // tree
  7. // #include <ext/pb_ds/hash_policy.hpp> // hash
  8. // #include <ext/pb_ds/trie_policy.hpp> // trie
  9. // #include <ext/pb_ds/priority_queue.hpp> // priority_queue
  10. // using namespace __gnu_pbds;
  11.  
  12. #include <bits/stdc++.h>
  13. using namespace std;
  14.  
  15. #define X first
  16. #define Y second
  17. #define ALL(x) x.begin(), x.end()
  18. #define RALL(x) x.rbegin(), x.rend()
  19. #define Push push_back
  20.  
  21. using lli = long long;
  22. using pll = pair<lli, lli>;
  23. using Double = long double;
  24. template<typename T>
  25. using Vector = vector<vector<T>>;
  26. template<typename T>
  27. using priority = priority_queue<T>;
  28.  
  29. const lli mod = 1E9 + 7;
  30. const Double PI = 3.1415926535846;
  31. const Double eps = 1e-8;
  32.  
  33. lli fastPow(lli base, lli exp, lli module = mod) {
  34.     lli ans = 1;
  35.     base %= module;
  36.     while (exp) {
  37.         if (exp & 1) ans = ans * base % module;
  38.         base = base * base % module;
  39.         exp >>= 1;
  40.     }
  41.     return ans;
  42. }
  43.  
  44. bool millerRabin(lli n, lli a) {
  45.     /*
  46.      * n < 4,759,123,141     3 : {2, 7, 61}
  47.      * n < 1,122,004,669,633 4 : {2, 13, 23, 1662803}
  48.      * n < 3,474,749,660,383 6 : {p in [2, 13]}
  49.      * n < 2^64                  7 :  
  50.      * {2, 325, 9375, 28178, 450775, 9780504, 1795265022}
  51.      *
  52.      * else, random everytime gives a 75% of correction
  53.      */
  54.      
  55.     if (n < 2) return 0;
  56.     if ((a = a%n) == 0) return 1;
  57.     if (n & 1 ^ 1) return n == 2;
  58.      
  59.     lli lowb = (n - 1) & -(n - 1);
  60.     lli tmp = (n - 1) / lowb; // lowbit of (n-1)
  61.     lli t = __lg(lowb);
  62.     lli x = 1;
  63.      
  64.     for (; tmp; tmp /= 2, a = a*a%n) {
  65.         if (tmp & 1) x = x * a % n;
  66.     }
  67.      
  68.     if (x == 1 or x == n - 1) return 1;
  69.      
  70.     while (--t) {
  71.         if ((x = x*x%n) == n - 1) return 1;
  72.     }
  73.      
  74.     return 0;
  75. }
  76.  
  77. void solve() {
  78.     string s, t;
  79.     getline(cin, s);
  80.     getline(cin, t);
  81.     vector<int> op;
  82.      
  83.     for (auto &x : s) {
  84.         if (x == ',') x = ' ';
  85.     }
  86.      
  87.     bool in = false;
  88.     for (auto &x : t) {
  89.         if (x == '[') {
  90.             in = true;
  91.         }
  92.         else if (x == ']') {
  93.             if (in) in = 0, op.Push(1);
  94.         }
  95.         if (in and x == ',') in = 0, op.Push(2);
  96.         if (in and x == '^') in = 0, op.Push(3);
  97.         if (in and x == '<') in = 0, op.Push(4);
  98.          
  99.         if (!isdigit(x)) x = ' ';
  100.     }
  101.      
  102.     // cout << s << "\n" << t << "\n";
  103.      
  104.     stringstream ss;
  105.     ss << s << t;
  106.      
  107.     int N, X;
  108.     ss >> N >> X;
  109.      
  110.     vector<lli> money(N, X);
  111.      
  112.     lli _A, _B, _X;
  113.     for (auto x : op) {
  114.         if (x == 1) {
  115.             ss >> _A >> _B;
  116.             money[_B] += money[_A] / 2;
  117.             money[_A] = (money[_A] + 1) / 2;
  118.         }
  119.         if (x == 2) {
  120.             ss >> _A >> _B >> _X;
  121.             money[_B] += min(money[_A], _X);
  122.             money[_A] = max(0LL, money[_A] - _X);
  123.         }
  124.         if (x == 3) {
  125.             ss >> _A >> _X;
  126.             money[_A] += _X;
  127.         }
  128.         if (x == 4) {
  129.             ss >> _A >> _B;
  130.             swap(money[_A], money[_B]);
  131.         }
  132.     }
  133.      
  134.     cout << money[0];
  135.     for (int i = 1; i < N; ++i) cout << "," << money[i];
  136.     cout << "\n";
  137. }
  138.  
  139. int main() {
  140.     int t = 1;
  141.     // cin >> t;
  142.     while (t--) {
  143.         solve();
  144.     }
  145.     return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement