Submission #1207090

#TimeUsernameProblemLanguageResultExecution timeMemory
1207090kiteyuDeda (COCI17_deda)C++20
140 / 140
515 ms40420 KiB
#include<bits/stdc++.h> #define lb lower_bound #define f first #define s second using namespace std; const int inf = 1e9 + 7; int n, p; char c[200005]; int a[200005], x[200005]; vector<int> v; set<int> bit[200005]; int id(int x){ return lower_bound(v.begin(),v.end(),x) - v.begin() + 1; } int main(){ cin >> n >> p; for(int i = 1 ; i <= p ; ++i){ cin >> c[i] >> x[i] >> a[i]; v.push_back(x[i]); } sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); int m = v.size(); for(int i = 1 ; i <= p ; ++i){ if(c[i] == 'M'){ for(int idx = id(x[i]);idx <= m ; idx += (idx & -idx)) bit[idx].insert(a[i]); } else{ //cout << ":v\n"; int ans = inf; for(int idx = id(x[i]) ; idx ; idx -= (idx & -idx)) if(!bit[idx].empty() && bit[idx].lower_bound(a[i]) != bit[idx].end()) ans = min(ans,*bit[idx].lower_bound(a[i])); cout << (ans == inf ? -1 : ans)<< '\n'; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...