SHARE
TWEET

Untitled

a guest Nov 18th, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. map <int, int> a;
  8. int n;
  9.  
  10. int main()
  11. {
  12.     ios_base::sync_with_stdio(false);
  13.     cin >> n;
  14.     char last = 0;
  15.     int lastans = -1;
  16.  
  17.     for(int i = 1; i <= n; i++){
  18.         char foo;
  19.         int bar;
  20.         cin >> foo >> bar;
  21.         if(foo == '?'){
  22.             auto next = a.lower_bound(bar);
  23.             if( (next->second) == 0 ){
  24.                 cout << -1;
  25.                 lastans = -1;
  26.             } else{
  27.                 cout << next->second;
  28.                 lastans = next->second;
  29.             }
  30.             cout << endl;
  31.         } else{
  32.             if(last == '?' && lastans != -1){
  33.                 a[(bar + lastans) % (int)1e9] = (bar + lastans) % (int)1e9;
  34.             } else{
  35.                 a[bar] = bar;
  36.             }
  37.         }
  38.         last = foo;
  39.     }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top