Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- using namespace __gnu_pbds;
- using namespace std;
- const int MOD = 1000000000;
- typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
- int main() {
- set <int> s;
- int q, x, tmpa = 0;
- char type, tmpc = '+';
- cin >> q;
- while (q --) {
- cin >> type >> x;
- if (type == '+') {
- if (tmpc == '+')
- s.insert (x);
- else
- s.insert ((x + tmpa) % MOD);
- } else {
- set <int> :: iterator it = s.lower_bound (x);
- if (*it == x) {
- tmpa = x;
- cout << tmpa << endl;
- continue;
- }
- if (it == s.end())
- tmpa = -1, cout << tmpa << endl;
- else
- tmpa = *(it), cout << tmpa << endl;
- }
- tmpc = type;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment