답안 #880605

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880605 2023-11-29T17:19:36 Z heeheeheehaaw 입자 가속기 (IZhO11_collider) C++17
100 / 100
78 ms 8592 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 604 KB Output is correct
2 Correct 7 ms 696 KB Output is correct
3 Correct 12 ms 3420 KB Output is correct
4 Correct 45 ms 7280 KB Output is correct
5 Correct 78 ms 7252 KB Output is correct
6 Correct 64 ms 7760 KB Output is correct
7 Correct 70 ms 8532 KB Output is correct
8 Correct 60 ms 8516 KB Output is correct
9 Correct 74 ms 8592 KB Output is correct
10 Correct 64 ms 8540 KB Output is correct