https://cn.vjudge.net/contest/296345#problem/K
总结:主席树
反思:scanf分开写都会tle~~
#include<bits/stdc++.h>
using namespace std;
#define sfi(i) scanf("%d",&i)
/*#define sfs(i) scanf("%s",(i))
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-8
#define PI acos(-1.0)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))<eps)
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
/*
//----------------------------------------------------------
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar()
{
if(head==tail)
{
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return*head++;
}
inline int read()
{
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
return x*f;
}
//----------------------------------------------------------
*/
const int maxn=1e5+9;
const int mod=1e9+7;
struct node
{
int ls,rs,sum;
bool friend operator < (node a, node b)
{
return a.rs>b.rs;
}
}tree[maxn*40];
int rt[maxn],tot;
void update(int &now,int old,int l,int r,int pos,int x)
{
now=++tot;
tree[now]=tree[old];
tree[now].sum+=x;
if(l==r) return ;
int mid=(l+r)>>1;
if(pos<=mid) update(tree[now].ls,tree[old].ls,l,mid,pos,x);
else update(tree[now].rs,tree[old].rs,mid+1,r,pos,x);
}
int query(int now,int l,int r,int k)
{
if(l==r) return l;
int mid=(l+r)>>1;
int cnt=tree[tree[now].ls].sum;
if(k<=cnt) return query(tree[now].ls,l,mid,k);
else return query(tree[now].rs,mid+1,r,k-cnt);
}
priority_queue<node>q;
void init()
{
tot=0;
while(!q.empty()) q.pop();
}
int main()
{
//FAST_IO;
//freopen("input.txt","r",stdin);
int T;
//T=read();
scanf("%d",&T);
for(int cas=1;cas<=T;cas++)
{
printf("Case %d:\n",cas);
init();
int E;
//E=read();
sfi(E);
for(int i=1;i<=E;i++)
{
rt[i]=rt[i-1];
int op;
//op=read();
sfi(op);
if(op==1)
{
int l,r,v;
//l=read();
//v=read();
//r=read();
//sfi(l);
//sfi(v);
//sfi(r);
scanf("%d %d %d", &l, &v, &r);
q.push(node{l,r,v});
update(rt[i],rt[i],1,(int)1e6,v,1);
}
else
{
int k,t;
//t=read();
//k=read();
//sfi(t);
//sfi(k);
scanf("%d %d", &t, &k);
while(!q.empty()&&q.top().rs<t)
{
update(rt[i],rt[i],1,(int)1e6,q.top().sum,-1);
q.pop();
}
if(tree[rt[i]].sum<k) printf("-1\n");
else printf("%d\n",query(rt[i],1,(int)1e6,k));
}
}
}
return 0;
}