#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 = 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 + 1, 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]
collider.cpp:39:37: warning: 'poz2' may be used uninitialized in this function [-Wmaybe-uninitialized]
39 | int sum = 0, val, poz1, poz2, idx1, idx2;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
1116 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |