Submission #1126881

#TimeUsernameProblemLanguageResultExecution timeMemory
1126881fryingducDeda (COCI17_deda)C++17
20 / 140
261 ms19496 KiB
#include "bits/stdc++.h"
using namespace std;

#ifdef duc_debug
#include "bits/debug.h"
#else
#define debug(...)
#endif

const int maxn = 2e5 + 5;
int n, q;
map<int, int> bit[maxn];
void update(int x, int val) {
  for(int i = x; i > 0; i -= i & (-i)) {
    auto it = bit[i].lower_bound(val);
    while(it != bit[i].end()) {
      if(it->second > x) {
        it = bit[i].erase(it);
      } else break;
    }
    bit[i].insert(make_pair(val, x));
  }
}
int get(int i, int val) {
  int res = 2e9;
  for(; i <= n; i += i & (-i)) {
    auto it = bit[i].upper_bound(val);
    if(it != bit[i].begin()) {
      it--;
      res = min(res, it->second);
    }
  } 
  return res;
}
void solve() {
  cin >> n >> q;
  while(q--) {
    char op; cin >> op;
    if(op == 'M') {
      int x, a; cin >> x >> a;
      update(a, x);
      
    } else {
      int y, b; cin >> y >> b;
      int res = get(b, y);
      cout << (res > 1e9 ? -1 : res) << '\n';
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(0); 
  cin.tie(0);

  solve();

  return 0;
}


#Verdict Execution timeMemoryGrader output
Fetching results...