// #include C { #include #include #include #include #include // } // #include C++ { #include #include #include #include #include #include #include #include #include #include #include #include #include // } using namespace std; // #typedef { typedef long long int64; typedef unsigned long long uint64; typedef pair PII; typedef pair PLL; typedef pair PDD; // } // #parameter{ #define LEN 2 #ifdef DEBUG_MODE #define TYPE decltype #define RF(filename) {freopen((filename), "r", stdin);} #define WF(filename) {freopen((filename), "w", stdout);} #define DEBUG printf #else #define TYPE __typeof #define RF(filename) {;} #define WF(filename) {;} #define DEBUG(...) #endif // #define { #define SZ(a) ((int)(a).size()) #define X first #define Y second #define MP make_pair #define L(x) ((x)<<1) #define R(x) ((x)<<1 | 1) #define max3(x, y, z) (max(max((x), (y)), (z))) #define min3(x, y, z) (min(min((x), (y)), (z))) #define BIT(x, i) (((x) >> (i)) & 1) #define ALL(it) (it).begin(), (it).end() #define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++) ///////////////////////////////////////////////////////////// const double PI = acos(-1.0); const double EPS = 1e-6; #define MAX_N 100005 #define MAX_M 5005 #define MAXX 0x3f #define UPPER 2147483647LL #define INF ((1 << 30) - 1) #define BINF ((1LL << 62) - 1LL) #define NONE -1 #define NIL 0 // } ///////////////////////////////////////////////////////////// vector V; struct Node{ PLL data[65]; int sz; Node(){ sz = 0; } void Append(int64 key, int64 value){ data[sz].X = key; data[sz].Y = value; sz++; } inline Node operator - (const Node &rhs){ Node newNode; for (int i = 0; i < sz; i++) newNode.Append(data[i].X, data[i].Y - rhs.data[i].Y); return newNode; } void Output(){ /*for (int i = 0; i < sz; i++) printf("%lld %lld\n", data[i].X, data[i].Y); puts("============");*/ } int64 Find(int64 k){ sort(data, data + sz); for (int i = 0; i < sz; i++){ if (k <= data[i].Y) return data[i].X; k -= data[i].Y; } return NONE; } }; Node f(int64 x){ int m = SZ(V); int ending = max(0, m - 60); int64 gap = 2LL; int64 offset = 1LL; Node node; for (int k = m - 1; k >= ending; k--){ int64 cnt = (x+offset) / gap; node.Append(1LL * V[k], cnt); gap <<= 1; offset <<= 1; } //node.Output(); return node; } ///////////////////////////////////////////////////////////// int main(){ RF("input.txt"); //WF("output.txt"); int n; scanf("%d", &n); while (n--){ int opcode; scanf("%d", &opcode); if (opcode == 1){ int w; scanf("%d", &w); V.push_back(w); } else{ int64 L, R, k; scanf("%I64d %I64d %I64d", &L, &R, &k); Node node = f(R) - f(L - 1); printf("%I64d\n", node.Find(k)); } } return 0; }