Submission #859938

# Submission time Handle Problem Language Result Execution time Memory
859938 2023-10-11T08:33:18 Z aykhn Collider (IZhO11_collider) C++14
0 / 100
1891 ms 262144 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

// author : aykhn

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

#define pb push_back
#define ins insert
#define mpr make_pair
#define all(v) v.begin(), v.end()
#define bpc __builtin_popcount
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define int ll
#define infll 0x3F3F3F3F3F3F3F3F
#define inf 0x3F3F3F3F
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MXN = 1e6 + 5;
const int B = 1000 + 5;

int n;
string s;
deque<char> dq[B];
string str[B];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int q;
    cin >> n >> q;
    while (n >= 2000)
    {
        cout << "skibidi toilet" << '\n';
    }
    cin >> s;
    int j = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (i && i % B == 0) j++;
        dq[j].push_back(s[i]);
        str[j].push_back(s[i]);
    }
    while (q--)
    {
        char ch;
        cin >> ch;
        if (ch == 'a')
        {
            int l, r;
            cin >> l >> r;
            if (l == r) continue;
            l--;
            r--;
            int type = 0;
            if (l > r)
            {
                type = 1;
                swap(l, r);
            }
            if (!type)
            {
                int j = l/B;
                int id = l - j * B;
                int k = 0;
                auto it = dq[j].begin();
                while (k++ < id) it++;
                char del = *it;
                dq[j].erase(it);
                for (int i = j + 1; i <= r/B; j++)
                {
                    dq[i - 1].push_back(dq[i].front());
                    dq[i].pop_front();
                }
                j = r/B;
                id = r - j * B;
                k = 0;
                auto it1 = dq[j].begin();
                while (k++ < id) it1++;
                dq[j].ins(it1, del);
            }
            else
            {
                int j = r/B;
                int id = r - j * B;
                int k = 0;
                auto it = dq[j].begin();
                while (k++ < id) it++;
                char del = *it;
                dq[j].erase(it);
                for (int i = j - 1; i >= l/B; j--)
                {
                    dq[i + 1].push_front(dq[i].back());
                    dq[i].pop_back();
                }
                id = l - l/B*B;
                k = 0;
                auto it1 = dq[l/B].begin();
                while (k++ < id) it1++;
                dq[l/B].ins(it1, del);
            }
        }
        else
        {
            int id;
            cin >> id;
            id--;
            int j = id/B;
            id -= j*B;
            int k = 0;
            auto it = dq[j].begin();
            while (k++ < id) it++;
            cout << *it << '\n';
        }
    }
}

Compilation message

collider.cpp: In function 'int main()':
collider.cpp:45:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i = 0; i < s.length(); i++)
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Correct 7 ms 1112 KB Output is correct
3 Runtime error 1891 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -