Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <map>
- #include <algorithm>
- using namespace std;
- map <int, int> a;
- int n;
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin >> n;
- char last = 0;
- int lastans = -1;
- for(int i = 1; i <= n; i++){
- char foo;
- int bar;
- cin >> foo >> bar;
- if(foo == '?'){
- auto next = a.lower_bound(bar);
- if( (next->second) == 0 ){
- cout << -1;
- lastans = -1;
- } else{
- cout << next->second;
- lastans = next->second;
- }
- cout << endl;
- } else{
- if(last == '?' && lastans != -1){
- a[(bar + lastans) % (int)1e9] = (bar + lastans) % (int)1e9;
- } else{
- a[bar] = bar;
- }
- }
- last = foo;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement