# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
880597 | heeheeheehaaw | 입자 가속기 (IZhO11_collider) | C++17 | 86 ms | 9560 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |