Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define gs(_obj_) (int)(_obj_.size())
- using namespace std;
- using ll = long long;
- vector<vector<int>> v;
- vector<int> ans;
- const int sz = 1024 + 256;
- void insert_at_pos(vector<int> & a, size_t ind, int val){
- a.push_back(val);
- if(ind < 0) {
- while(true);
- }
- for(size_t i = a.size() - 1; i > ind; i--){
- swap(a[i], a[i-1]);
- }
- }
- void get_sub_ans(vector<int> & a, int & answer, int f, int t){
- for(int i = f; i <= t; i++){
- answer = min(answer, a[i]);
- }
- }
- void rebuild(){
- vector<int> tot;
- for(size_t i = 0; i < v.size(); i++){
- for(int val : v[i]){
- tot.push_back(val);
- }
- v[i].clear();
- }
- v.clear();
- ans.clear();
- for(size_t i = 0; i < tot.size(); i += sz){
- vector<int> nxt;
- for(size_t j = i; j < min(tot.size(), i + sz); j++){
- nxt.push_back(tot[j]);
- }
- v.push_back(nxt);
- ans.push_back(*min_element(nxt.begin(), nxt.end()));
- }
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int q;
- cin>>q;
- v = {{}};
- ans = {2000'000'000};
- for(int itr = 1; itr <= q; itr++){
- if(itr % sz == 0) {
- rebuild();
- }
- char type;
- cin>>type;
- if(type == '+') {
- size_t ind;
- int val;
- cin>>ind>>val;
- size_t cur = 0;
- for(size_t i = 0; i < v.size(); i++){
- if(cur + v[i].size() > ind || i == v.size() - 1){
- insert_at_pos(v[i], ind - cur, val);
- ans[i] = min(ans[i], val);
- break;
- } else {
- cur += v[i].size();
- }
- }
- } else {
- int answer = 2e9;
- int l, r;
- cin>>l>>r;
- l--,r--;
- int cur_l = 0, cur_r;
- for(size_t i = 0; i < v.size(); i++){
- cur_r = cur_l + v[i].size() - 1;
- if(l <= cur_l && r >= cur_r){
- answer = min(answer, ans[i]);
- } else {
- int real_l = max(0, l - cur_l), real_r = min(gs(v[i]) - 1, r - cur_l);
- get_sub_ans(v[i], answer, real_l, real_r);
- }
- cur_l = cur_r + 1;
- }
- cout<<answer<<"\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement