func_code_string: #include <bits/stdc++.h>   using namespace std;   constexpr int MAXN = 1 << 30;   struct tournament {     struct Node {       Node* parent;       set<int, greater<int>> blocked;       Node* left = nullptr;       Node* right = nullptr;       Node(Node* parent) : parent(parent) {}     }* root = new Node(nullptr);     set<int, greater<int>>::iterator it;     void update(int x, int start, int end, int lo = 0, int hi = MAXN,                 Node* node = nullptr) {       if (node == nullptr) node = root;       if (lo >= end || hi <= start) return;       if (lo >= start && hi <= end) {         node->blocked.insert(x);         return;       }       int mid = (lo + hi) / 2;       if (mid > start) {         if (node->left == nullptr) node->left = new Node(node);         update(x, start, end, lo, mid, node->left);       }       if (mid < end) {         if (node->right == nullptr) node->right = new Node(node);         update(x, start, end, mid, hi, node->right);       }     }     int query(int x, int pos) {       Node* node = root;       int lo = 0, hi = MAXN;       int sol = -1;       while (node != nullptr) {         if ((it = node->blocked.lower_bound(x)) != node->blocked.end() &&             *it > sol)           sol = *it;         int mid = (lo + hi) / 2;         if (pos < mid)           hi = mid, node = node->left;         else           lo = mid, node = node->right;       }       return sol;     }   } rows, cols;   set<int> bio;   int unzipA[200100], unzipB[200100];   pair<int, int> a[200100], b[200100];   char dirs[200100];   int main() {     ios_base::sync_with_stdio(false);     int n, q, i, j, x;     char dir;     cin >> n >> q;     rows.update(-1, 0, MAXN), cols.update(-1, 0, MAXN);     for (i = 0; i < q; ++i) {       cin >> b[i].first >> a[i].first >> dirs[i];       --a[i].first, --b[i].first;       a[i].second = b[i].second = i;     }     sort(a, a + q);     sort(b, b + q);     new (unzipA - 1) int;     new (unzipB - 1) int;     unzipA[-1] = unzipB[-1] = -1;     for (i = 0; i < q; ++i) {       unzipA[i] = a[i].first;       unzipB[i] = b[i].first;       a[i].first = b[i].first = i;     }     sort(a, a + q, [](const pair<int, int>& a, const pair<int, int>& b) {       return a.second < b.second;     });     sort(b, b + q, [](const pair<int, int>& a, const pair<int, int>& b) {       return a.second < b.second;     });     for (int k = 0; k < q; ++k) {       i = a[k].first;       j = b[k].first;       dir = dirs[k];       if (bio.count(MAXN + i - j)) {         cout <<  0 n ;         continue;       }       bio.insert(MAXN + i - j);       switch (dir) {         case  U :           x = rows.query(i, j);           cout << unzipA[i] - unzipA[x] << endl;           cols.update(j, x, i);           break;         case  L :           x = cols.query(j, i);           cout << unzipB[j] - unzipB[x] << endl;           rows.update(i, x + 1, j + 1);           break;       }     }   }   