Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #include <boost/multiprecision/cpp_int.hpp>
- // using namespace boost::multiprecision;
- // #include <bits/extc++.h>
- // #include <ext/pb_ds/assoc_container.hpp>
- // #include <ext/pb_ds/tree_policy.hpp> // tree
- // #include <ext/pb_ds/hash_policy.hpp> // hash
- // #include <ext/pb_ds/trie_policy.hpp> // trie
- // #include <ext/pb_ds/priority_queue.hpp> // priority_queue
- // using namespace __gnu_pbds;
- #include <bits/stdc++.h>
- using namespace std;
- #define X first
- #define Y second
- #define ALL(x) x.begin(), x.end()
- #define RALL(x) x.rbegin(), x.rend()
- #define Push push_back
- using lli = long long;
- using pll = pair<lli, lli>;
- using Double = long double;
- template<typename T>
- using Vector = vector<vector<T>>;
- template<typename T>
- using priority = priority_queue<T>;
- const lli mod = 1E9 + 7;
- const Double PI = 3.1415926535846;
- const Double eps = 1e-8;
- lli fastPow(lli base, lli exp, lli module = mod) {
- lli ans = 1;
- base %= module;
- while (exp) {
- if (exp & 1) ans = ans * base % module;
- base = base * base % module;
- exp >>= 1;
- }
- return ans;
- }
- bool millerRabin(lli n, lli a) {
- /*
- * n < 4,759,123,141 3 : {2, 7, 61}
- * n < 1,122,004,669,633 4 : {2, 13, 23, 1662803}
- * n < 3,474,749,660,383 6 : {p in [2, 13]}
- * n < 2^64 7 :
- * {2, 325, 9375, 28178, 450775, 9780504, 1795265022}
- *
- * else, random everytime gives a 75% of correction
- */
- if (n < 2) return 0;
- if ((a = a%n) == 0) return 1;
- if (n & 1 ^ 1) return n == 2;
- lli lowb = (n - 1) & -(n - 1);
- lli tmp = (n - 1) / lowb; // lowbit of (n-1)
- lli t = __lg(lowb);
- lli x = 1;
- for (; tmp; tmp /= 2, a = a*a%n) {
- if (tmp & 1) x = x * a % n;
- }
- if (x == 1 or x == n - 1) return 1;
- while (--t) {
- if ((x = x*x%n) == n - 1) return 1;
- }
- return 0;
- }
- void solve() {
- string s, t;
- getline(cin, s);
- getline(cin, t);
- vector<int> op;
- for (auto &x : s) {
- if (x == ',') x = ' ';
- }
- bool in = false;
- for (auto &x : t) {
- if (x == '[') {
- in = true;
- }
- else if (x == ']') {
- if (in) in = 0, op.Push(1);
- }
- if (in and x == ',') in = 0, op.Push(2);
- if (in and x == '^') in = 0, op.Push(3);
- if (in and x == '<') in = 0, op.Push(4);
- if (!isdigit(x)) x = ' ';
- }
- // cout << s << "\n" << t << "\n";
- stringstream ss;
- ss << s << t;
- int N, X;
- ss >> N >> X;
- vector<lli> money(N, X);
- lli _A, _B, _X;
- for (auto x : op) {
- if (x == 1) {
- ss >> _A >> _B;
- money[_B] += money[_A] / 2;
- money[_A] = (money[_A] + 1) / 2;
- }
- if (x == 2) {
- ss >> _A >> _B >> _X;
- money[_B] += min(money[_A], _X);
- money[_A] = max(0LL, money[_A] - _X);
- }
- if (x == 3) {
- ss >> _A >> _X;
- money[_A] += _X;
- }
- if (x == 4) {
- ss >> _A >> _B;
- swap(money[_A], money[_B]);
- }
- }
- cout << money[0];
- for (int i = 1; i < N; ++i) cout << "," << money[i];
- cout << "\n";
- }
- int main() {
- int t = 1;
- // cin >> t;
- while (t--) {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement