답안 #880597

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880597 2023-11-29T17:16:46 Z heeheeheehaaw 입자 가속기 (IZhO11_collider) C++17
100 / 100
86 ms 9560 KB
#include <bits/stdc++.h>

using namespace std;

vector<int> buckets[10005];
int v[1000005];
char tochar[] = {0, 'x', 'y', 'z', 'x'};

int main()
{
    int n, m, sqn;
    cin>>n>>m;
    sqn = (int)sqrt(n);
    int cnt = 1;
    for(int i = 1; i <= n; i++)
    {
        char c;
        cin>>c;
        if(c == 'x') v[i] = 1;
        else if(c == 'y') v[i] = 2;
        else v[i] = 3;

        buckets[cnt].push_back(v[i]);
        if(i % sqn == 0)
            cnt++;
    }

    for(int i = 1; i <= m; i++)
    {
        char tip;
        cin>>tip;

        if(tip == 'a')
        {
            int a, b;
            cin>>a>>b;
            if(a == b)
                continue;
            int sum = 0, val, poz1, poz2, idx1, idx2;
            for(int j = 1; j <= cnt; j++)
            {
                if(a > sum && a <= sum + buckets[j].size())
                {
                    val = buckets[j][a - sum - 1];
                    idx1 = j;
                    poz1 = a - sum - 1;
                }
                if(b > sum && b <= sum + buckets[j].size())
                {
                    idx2 = j;
                    poz2 = b - sum - 1;
                }

                sum += buckets[j].size();
            }

            //cout<<poz1<<" "<<poz2<<'\n';
            if(a < b)
            {
                if(idx1 == idx2)
                {
                    buckets[idx1].erase(buckets[idx1].begin() + poz1);
                    buckets[idx2].insert(buckets[idx2].begin() + poz2, val);
                }
                else
                {
                    buckets[idx1].erase(buckets[idx1].begin() + poz1);
                    buckets[idx2].insert(buckets[idx2].begin() + poz2 + 1, val);
                }
            }
            else
            {
                if(idx1 == idx2)
                {
                    buckets[idx1].erase(buckets[idx1].begin() + poz1);
                    buckets[idx2].insert(buckets[idx2].begin() + poz2, val);
                }
                else
                {
                    buckets[idx1].erase(buckets[idx1].begin() + poz1);
                    buckets[idx2].insert(buckets[idx2].begin() + poz2, val);
                }
            }

            /*for(int j = 1; j <= cnt; j++)
            {
                cout<<buckets[j].size()<<": ";
                for(auto k : buckets[j])
                    cout<<tochar[k];
                cout<<'\n';
            }

            cout<<'\n';*/
        }
        else
        {
            int a;
            cin>>a;
            int sum = 0, val;
            for(int j = 1; j <= cnt; j++)
            {
                if(a > sum && a <= sum + buckets[j].size())
                {
                    val = buckets[j][a - sum - 1];
                    break;
                }

                sum += buckets[j].size();
            }

            cout<<tochar[val]<<'\n';
        }
    }
    return 0;
}

Compilation message

collider.cpp: In function 'int main()':
collider.cpp:42:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |                 if(a > sum && a <= sum + buckets[j].size())
      |                               ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
collider.cpp:48:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |                 if(b > sum && b <= sum + buckets[j].size())
      |                               ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
collider.cpp:102:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |                 if(a > sum && a <= sum + buckets[j].size())
      |                               ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
collider.cpp:111:29: warning: 'val' may be used uninitialized in this function [-Wmaybe-uninitialized]
  111 |             cout<<tochar[val]<<'\n';
      |                   ~~~~~~~~~~^
collider.cpp:60:17: warning: 'idx2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |                 if(idx1 == idx2)
      |                 ^~
collider.cpp:60:17: warning: 'idx1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 7 ms 600 KB Output is correct
3 Correct 11 ms 3928 KB Output is correct
4 Correct 46 ms 8172 KB Output is correct
5 Correct 57 ms 8320 KB Output is correct
6 Correct 63 ms 9044 KB Output is correct
7 Correct 86 ms 9552 KB Output is correct
8 Correct 56 ms 9560 KB Output is correct
9 Correct 76 ms 9556 KB Output is correct
10 Correct 68 ms 9556 KB Output is correct