Guest User

686

a guest
Aug 8th, 2017
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3.  
  4. using namespace __gnu_pbds;
  5. using namespace std;
  6.  
  7. const int MOD = 1000000000;
  8.  
  9. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
  10.  
  11. int main() {
  12.     set <int> s;
  13.     int q, x, tmpa = 0;
  14.     char type, tmpc = '+';
  15.     cin >> q;
  16.     while (q --) {
  17.         cin >> type >> x;
  18.         if (type == '+') {
  19.             if (tmpc == '+')
  20.                 s.insert (x);
  21.             else
  22.                 s.insert ((x + tmpa) % MOD);
  23.         } else {
  24.             set <int> :: iterator it = s.lower_bound (x);
  25.             if (*it == x) {
  26.                 tmpa = x;
  27.                 cout << tmpa << endl;
  28.                 continue;
  29.             }
  30.             if (it == s.end())
  31.                 tmpa = -1, cout << tmpa << endl;
  32.             else
  33.                 tmpa = *(it), cout << tmpa << endl;
  34.         }
  35.         tmpc = type;
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment