Advertisement
a53

Set

a53
Oct 13th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <fstream>
  2. #include <set>
  3. using namespace std;
  4. ifstream f("set.in");
  5. ofstream g("set.out");
  6. set <int> S;
  7. int n,op,x,y,t;
  8.  
  9. int main()
  10. {
  11. f>>n;
  12. for(int i=1;i<=n;++i)
  13. {
  14. f>>op;
  15. if(op==1)
  16. {
  17. f>>x;
  18. S.insert(x);
  19. }
  20. if(op==2)
  21. {
  22. f>>x;
  23. t=*S.lower_bound(x);
  24. if(S.empty()) /// Daca setul S e vid
  25. g<<-1<<'\n';
  26. else
  27. if(x<=*S.rbegin()) /// Daca x se afla in set
  28. g<<t<<'\n';
  29. else
  30. g<<-1<<'\n';
  31. }
  32. if(op==3)
  33. {
  34. f>>x>>y;
  35. if(y>=*S.begin())
  36. while(S.lower_bound(x)!=S.end()&&*S.upper_bound(x)<=y)
  37. S.erase(*S.lower_bound(x));
  38. }
  39. }
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement