#include <bits/extc++.h>
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
ll linf = 1e15+1;
inline void scoobydoobydoo(){
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
using namespace __gnu_pbds;
template<class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>;
int main(){
scoobydoobydoo();
int n, m; cin >> n >> m;
Tree<pair<long double, int> > s; // %3 0 -> x, 1 -> y, 2 -> z
int counter = 1;
s.insert({0, -1});
for (long double i = 1; i <= n; i++){
char c; cin >> c;
if (c == 'x')s.insert({i*(1e11), 0});
else if (c == 'y')s.insert({i*(1e11), 1});
else s.insert({i*(1e11), 2});
}
s.insert({1e25, -1});
vector<char> ans;
for (int i = 0; i < m; i++){
char c; cin >> c;
if (c == 'a'){
int x, y; cin >> x >> y;
auto it = s.find_by_order(x);
int sec = (*it).second;
s.erase(it);
auto itr = s.find_by_order(y-1);
auto itr2 = s.find_by_order(y);
long double nVal = ((*itr).first + (*itr2).first)/2.0;
s.insert({nVal, sec});
} else {
int x; cin >> x;
auto it = s.find_by_order(x);
int sec = (*it).second;
if (sec == 0)ans.push_back('x');
else if (sec == 1)ans.push_back('y');
else ans.push_back('z');
}
//for (auto& e : s)cout << "(" << e.first << "," << e.second << "), ";
//cout << endl;
}
for (char c : ans)cout << c << endl;
return 0;
}
Compilation message
collider.cpp: In function 'int main()':
collider.cpp:38:9: warning: unused variable 'counter' [-Wunused-variable]
38 | int counter = 1;
| ^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
8 ms |
604 KB |
Output is correct |
3 |
Correct |
57 ms |
9972 KB |
Output is correct |
4 |
Correct |
669 ms |
76204 KB |
Output is correct |
5 |
Correct |
667 ms |
76388 KB |
Output is correct |
6 |
Correct |
768 ms |
85964 KB |
Output is correct |
7 |
Correct |
879 ms |
95408 KB |
Output is correct |
8 |
Correct |
832 ms |
95388 KB |
Output is correct |
9 |
Correct |
896 ms |
95572 KB |
Output is correct |
10 |
Correct |
854 ms |
95276 KB |
Output is correct |