/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 320.0 KiB
#3 Accepted 115ms 2.379 MiB
#4 Accepted 22ms 7.219 MiB
#5 Accepted 1ms 536.0 KiB
#6 Accepted 138ms 2.211 MiB
#7 Accepted 128ms 2.004 MiB
#8 Accepted 25ms 836.0 KiB
#9 Accepted 46ms 7.895 MiB
#10 Accepted 68ms 7.73 MiB
#11 Accepted 27ms 2.629 MiB
#12 Accepted 28ms 7.246 MiB

Code

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define MP make_pair
#define ll long long
#define F first
#define S second

const long long MOD=1e9+7;
/*
vector <int> primes;
int first_prime[(int)1e6+1];

void seive(){

  for (int i=2;i<=1e6;i++){
        if (first_prime[i]==0){
                first_prime[i]=i;
                primes.push_back(i);
            for (int j=i+i;j<=1e6;j+=i){
                    if (first_prime[j]==0)
                first_prime[j]=i;
            }
        }
  }
}





long long mulmod(long long x,long long y,long long m){
    return ((x%m)*(y%m))%m;
}

long long addmod(long long x,long long y,long long m){
    if (x+y>=m) return x-m+y;
    return x+y;
}

long long submod(long long x, long long y, long long m){
    if (x-y<0) return x-y+m;
    return x-y;
}

long long inv (long long x, long long m){
 return powmod(x,m-2,m);
}

struct DSU {
	vi e; void init(int N) { e = vi(N,-1); }
	int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
	bool sameSet(int a, int b) { return get(a) == get(b); }
	int size(int x) { return -e[get(x)]; }
	bool unite(int x, int y) { // union by size
		x = get(x), y = get(y); if (x == y) return 0;
		if (e[x] > e[y]) swap(x,y);
		e[x] += e[y]; e[y] = x; return 1;
	}
};

int longest_path(unordered_map< int, vector < int > >& tree,int n )
{
    vector < int > leafs ;
    vector < int > dgr ( n+1 );
    for ( auto el : tree )
    {
        dgr[el.first] = el.second.size() ;
    }
    for ( int i = 1 ; i <= n ; i++ )
    {
        if ( dgr[i] == 1 ) leafs.pb(i) ;
    }
    int ans = 2 ;
    while ( leafs.size() > 0 )
    {
        vector < int > new_leafs ;
        for ( auto el : leafs )
        {
            for ( auto nd : tree[el] )
            {
                dgr[nd] -- ;
                if ( dgr[nd] == 1 ) new_leafs.pb(nd) ;
            }
        }
        leafs = new_leafs ;
        if ( leafs.size() > 1 ) ans += 2 ;
        else if ( leafs.size() == 1 ) ans += 1 ;
    } // center is the last element in the leafs vector
    return ans ;
}

char a[16]={'0','1','2','3','4','5','6','7','8','9',
  'A','B','C','D','E','F'};
string tenToM(int n, int m)
{
  int temp=n;
  string result="";
  while (temp!=0)
  {
    result=a[temp%m]+result;
    temp/=m;
  }
  return result;
}

long long powmod(long long x,long long y,long long n){
    long long res=1;
    while(y>0){
        if (y&1){res=((res%n)*(x%n))%n;}
        x=((x%n)*(x%n))%n;
        y/=2;
    }
    return res;
}
long long mulmod(long long x,long long y,long long m){
    return ((x%m)*(y%m))%m;
}

ll modInverse ( ll n , ll Mod )
{
  return powmod ( n , Mod - 2 , Mod ) ;
}

const int N=1e5+5;
bool vis[N];
ll depth[N];
vector <int> leaf;

void dfs(int p, vector <vector <int> >& v){
    vis[p]=1;
    if (v[p].size()==1 && p!=1){leaf.pb(p); return;}
    for (int i=0;i<v[p].size();i++){
        if (!vis[v[p][i]]){
            depth[v[p][i]]=depth[p]+1;
            dfs(v[p][i],v);
        }
    }
}
ll fact[N];
void factorial(){

    fact[0]=1;
    for (int i=1;i<N;i++){
        fact[i]=(fact[i-1]*i)%MOD;
    }
}
ll ncr(long long n,long long r, long long p){
 return (fact[n]*modInverse(mulmod(fact[r],fact[n-r],p),p))%p;
}



int parent[5005][14],dep[5005],dep2[5005];
void dfs(int p, int x, vector <vector <int> >& v){
    if (v[x].size()==1 && x!=1){dep2[x]=1;return;}
    int d=0;
    for (int i=0;i<v[x].size();i++){
        if (v[x][i]==p)continue;
        parent[v[x][i]][0]=x;

        for (int j=1;j<14;j++){
            parent[v[x][i]][j]=parent[parent[v[x][i]][j-1]][j-1];
        }
        dep[v[x][i]]=dep[x]+1;
        dfs(x,v[x][i],v);
       d=max(d,dep2[v[x][i]]+1);
    }
    dep2[x]=d;
}
int bi_lift(int x,int k){

if (k>=dep[x]){return 1;}
    for ( int i=13;i>=0;i--){
        if (k>=(1<<i)){
            x=parent[x][i];
            k-=1<<i;
        }
    }
    return x;
}

int child(int p, int x, vector <vector <int> >& v){

    int ans=x;
    if (v[x].size()==1 && x!=1){return x;}
    int mx=0,ind=-1;
    for (int i=0;i<v[x].size();i++){
        if (v[x][i]==p)continue;
        else {
            if (mx<dep2[v[x][i]]){
                mx=dep2[v[x][i]];
                ind=i;
            }

        }
    }
    if (ind!=-1)
     ans=child(x,v[x][ind],v);
    return ans;

}

__int128 read() {
    __int128 x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
void print(__int128 x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}
bool cmp(__int128 x, __int128 y) { return x > y; }

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
  template<
	  typename Key, // Key type
	  typename Mapped, // Mapped-policy
	  typename Cmp_Fn = std::less<Key>, // Key comparison functor
	  typename Tag = rb_tree_tag, // Specifies which underlying data structure to use
	  template<
	  typename Const_Node_Iterator,
	  typename Node_Iterator,
	  typename Cmp_Fn_,
	  typename Allocator_>
	  class Node_Update = null_node_update, // A policy for updating node invariants
	  typename Allocator = std::allocator<char> > // An allocator type
	  class tree;
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;



struct segtr{
   int sz;
   vector <ll > pre,suf,ans,sum;

    void cmb(int x){
        sum[x]=sum[2*x]+sum[2*x+1];
        pre[x]=max(pre[2*x],sum[2*x]+pre[2*x+1]);
        suf[x]=max(suf[2*x+1],sum[2*x+1]+suf[2*x]);
        ans[x]=max({pre[x],suf[x],suf[2*x]+pre[2*x]});
    }

    void build(ll a[], int x, int lx, int rx){
        if (lx==rx){
            sum[x]=a[lx];
            pre[x]=suf[x]=ans[x]=max(0ll,a[lx]);
            return ;
        }
        int m=(lx+rx)/2;
        build(a,2*x,lx,m);
        build(a,2*x+1,m+1,rx);
        cmb(x);
    }

   void build(ll a[],int n){
       sz=1;
       while(sz<n){
        sz*=2;
       }
       pre.assign(2*sz,0ll);
       suf.assign(2*sz,0ll);
       ans.assign(2*sz,0ll);
       sum.assign(2*sz,0ll);
    build(a,1,1,sz);
   }

   void update(int i,ll v,int x, int lx, int rx){
    if (lx==rx){
        sum[x]=v;
            pre[x]=suf[x]=ans[x]=max(0ll,v);
            return ;
    }
    int m=(lx+rx)/2;
    if (i<=m){
        update(i,v,2*x,lx,m);
    }
    else {
        update(i,v,2*x+1,m+1,rx);
    }
    cmb(x);
   }

   void update(int i,ll v){
    update(i,v,1,1,sz);
   }

   ll pr(){
    return ans[1];
   }
};*/



void solve()
{

  string s;
  cin>>s;
  int q;
  cin>>q;
    bool ok=1;
    deque<char> l,r;
    while(q--){
        int c;
        cin>>c;
        if (c==1){
            ok=!ok;
        }
        else if (c==2){
            int d;
            char g;
            cin>>d>>g;
            if (d==1){
                if (ok){
                    l.push_front(g);
                }
                else {
                    r.push_back(g);
                }
            }
            else {
                if (ok){
                    r.push_back(g);
                }
                else {
                    l.push_front(g);
                }
            }
        }
    }
    if (!ok){
    reverse(l.begin(),l.end());
    reverse (r.begin(),r.end());
    for (auto it=r.begin();it!=r.end();it++){
        cout<<*it;
    }
    reverse (s.begin(),s.end());
    cout<<s;
       for (auto it=l.begin();it!=l.end();it++){
        cout<<*it;
        }
    }
    else {
        for (auto it=l.begin();it!=l.end();it++){
        cout<<*it;
    }

    cout<<s;
       for (auto it=r.begin();it!=r.end();it++){
        cout<<*it;
        }
    }
    cout<<endl;


}// end of solve function


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen( ".in" , "r" , stdin );


    int t=1;

    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++17 (G++ 13.2.0)
Submit At
2024-09-05 15:56:59
Judged At
2024-10-03 13:09:39
Judged By
Score
100
Total Time
138ms
Peak Memory
7.895 MiB