/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 113ms 3.422 MiB
#4 Accepted 66ms 7.711 MiB
#5 Accepted 2ms 536.0 KiB
#6 Accepted 128ms 2.305 MiB
#7 Accepted 121ms 2.0 MiB
#8 Accepted 24ms 1.02 MiB
#9 Accepted 106ms 8.219 MiB
#10 Accepted 111ms 7.883 MiB
#11 Accepted 36ms 3.672 MiB
#12 Accepted 74ms 7.344 MiB

Code

#include <iostream>
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pb push_back
#define vi vector<int>
#define vll vector<ll>
#define mp make_pair
#define pq priority_queue<int>
#define pi pair<int, int>
#define pll pair<ll, ll>
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define PI acos(-1)
const int M = 1e9 + 7;
ll binExp(ll a, ll b)
{
    int res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a;
        a *= a;
        b /= 2;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
    return (a / gcd(a, b)) * b;
}
ll sum(ll n)
{
    return n * (n + 1) / 2;
}
void solve()
{
    // abc
    // dabc
    // ea

    // cbad
    // cbade
    string s;
    cin >> s;
    int q;
    cin >> q;
    deque<char> v;
    for (auto &a : s)
        v.push_back(a);
    int f = 0;
    while (q--)
    {
        int ty;
        cin >> ty;
        if (ty == 1)
            f ^= 1;
        else
        {
            int i;
            cin >> i;
            char ch;
            cin >> ch;
            if (i == 1)
            {
                if (!f)
                    v.push_front(ch);
                else
                    v.push_back(ch);
            }
            else
            {
                if (f)
                    v.push_front(ch);
                else
                    v.push_back(ch);
            }
        }
    }
    if (f)
        reverse(all(v));
    for (auto &a : v)
        cout << a;
    cout << endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1088 Mr. Heart's String Challenge
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 15:49:24
Judged At
2024-09-05 15:49:24
Judged By
Score
100
Total Time
128ms
Peak Memory
8.219 MiB