답안 #859951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859951 2023-10-11T08:44:18 Z aykhn 입자 가속기 (IZhO11_collider) C++14
100 / 100
28 ms 3572 KB
#include <bits/stdc++.h>
 
// author : aykhn
 
using namespace std;
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
 
const int MXN = 1e6 + 5;
const int B = 1500;
 
int n;
string s;
deque<char> dq[B];
 
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int q;
    cin >> n >> q;
    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]);
    }
    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; i++)
                {
                    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; i--)
                {
                    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:36: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]
   36 |     for (int i = 0; i < s.length(); i++)
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1372 KB Output is correct
2 Correct 7 ms 1372 KB Output is correct
3 Correct 6 ms 1628 KB Output is correct
4 Correct 11 ms 3064 KB Output is correct
5 Correct 18 ms 3064 KB Output is correct
6 Correct 22 ms 3200 KB Output is correct
7 Correct 23 ms 3396 KB Output is correct
8 Correct 13 ms 3316 KB Output is correct
9 Correct 28 ms 3360 KB Output is correct
10 Correct 24 ms 3572 KB Output is correct