fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include<algorithm>
  4. #include <math.h>
  5. #include <iomanip>
  6. #include <stack>
  7. #include <string>
  8. #include <set>
  9. #include <map>
  10. using namespace std;
  11. int sz,q;
  12. int tables[(int)1e5+1],freq[(int)1e5+1];
  13. set<int>f_availble[(int)1e5+1];
  14. set<int>dis_sizes;
  15. int main(){
  16. cin>>sz>>q;
  17. for (int i=0; i<sz; i++) {
  18. cin>>tables[i];
  19. dis_sizes.insert(tables[i]);
  20. freq[tables[i]]++;
  21. f_availble[tables[i]].insert(i+1);
  22. }
  23. set<int>::iterator myit,t;
  24. for (int i=0; i<q; i++) {
  25. string what;
  26. int n;
  27. cin>>what>>n;
  28. if (what=="in") {
  29. myit = dis_sizes.lower_bound(n);
  30. if (myit==dis_sizes.end()) {
  31. cout<<"-1"<<endl;
  32. }
  33. else{
  34. freq[*myit]--;
  35. if (freq[*myit]==0) {
  36. dis_sizes.erase(myit);
  37. }
  38. cout<<*(f_availble[*myit].begin())<<endl;
  39. f_availble[*myit].erase(f_availble[*myit].begin());
  40. }
  41. }
  42. else{
  43. dis_sizes.insert(tables[n-1]);
  44. freq[tables[n-1]]++;
  45. f_availble[tables[n-1]].insert(n);
  46. }
  47. }
  48. return 0;
  49. }
Success #stdin #stdout 0s 6588KB
stdin
Standard input is empty
stdout
Standard output is empty