/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 348.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 108ms 2.422 MiB
#4 Time Exceeded ≥1101ms ≥1.621 MiB
#5 Accepted 1ms 532.0 KiB
#6 Time Exceeded ≥1100ms ≥976.0 KiB

Code

// PIPRA ||  HABIB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int        long long int
#define pb         push_back
#define all(x)     x.begin(),x.end()
#define allr(x)    x.rbegin(),x.rend()
#define ii         pair<int,int>
#define endl       "\n"


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rng(x,y) uniform_int_distribution<int>(x,y)(rng)
// must define int as long long
typedef uint64_t ull;
struct H {
    ull x; H(ull _x=0) : x(_x) {}
    H operator+(H o) { return x + o.x + (x + o.x < x); }
    H operator-(H o) { return *this + ~o.x; }
    H operator*(H o) { auto m = (__uint128_t)x * o.x;
        return H((ull)m) + (ull)(m >> 64); }
    ull get() const { return x + !~x; }
    bool operator==(H o) const { return get() == o.get(); }
    bool operator<(H o) const { return get() < o.get(); }
};
static const H C = (int)rng(1e10,1e12); // (order ~ 3e9; random also ok)
 
struct HashInterval {
    vector<H> ha, pw;
    HashInterval(string& str) : ha(str.size()+1), pw(ha) {   // HashInterval H(s)
        pw[0] = 1;
        for (int i = 0; i < str.size(); i++)
            ha[i+1] = ha[i] * C + str[i],
            pw[i+1] = pw[i] * C;
    }
    H hashInterval(int a, int b) { // hash [a, b) // 0-index based
        return ha[b] - ha[a] * pw[b - a];
    }
    void insert(char a){
        ha.pb(ha.back()*C + a);
        pw.pb(pw.back()*C);
    }
};
// auto x = H.hashInterval(0, 5);  int y = x.get()
// it gives a big value that's not fit in ll
// TC = O(1)


void pipra(){
    string s;
    cin >> s;

    int q;  cin >> q;
    int count = 0;

    while(q--){
        int type;
        cin >> type;
        count += (type == 1);

        if(type == 2){
            int d;  
            char ch;
            cin >> d >> ch;

            if(d == 1){
                if(count & 1){
                    s += ch;
                    reverse(all(s));
                }
                else{
                    string x = "";
                    x += ch;
                    x += s;
                    s = x;
                }
            }
            else{
                if(count & 1){
                    reverse(all(s));
                }
                s += ch;
            }
            count = 0;
        }
    }

    if(count & 1){
        reverse(all(s));
    }

    cout << s << endl;
}

int32_t main(){
    // HABIB
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);

    int t;    cin>>t;
    while(t--) {
        pipra();
    }
    return 0 ;
}

Information

Submit By
Type
Submission
Problem
P1088 Mr. Heart's String Challenge
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-14 13:23:36
Judged At
2024-10-14 13:23:36
Judged By
Score
20
Total Time
≥1101ms
Peak Memory
≥2.422 MiB