# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
880605 | heeheeheehaaw | Collider (IZhO11_collider) | C++17 | 78 ms | 8592 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |