E. Divan and a Cottage
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
#define Dow(i,j,k) for(int i=k;i>=j;--i)
#define ll long long
#define pb push_back
#define fir first
#define sec second
#define pb push_back
#define pa pair<int,int>
#define mk make_pair
using namespace std;
inline ll read()
{
ll t=0,dp=1;char c=getchar();
while(!isdigit(c)) {if(c=='-') dp=-1;c=getchar();}
while(isdigit(c)) t=t*10+c-48,c=getchar();
return t*dp;
}
inline void write(ll x){if(x<0) {putchar('-');x=-x;} if(x>=10) write(x/10);putchar(x%10+48);}
inline void writeln(ll x){write(x);puts("");}
inline void write_p(ll x){write(x);putchar(' ');}
const int N=2e6+5;
int mo=1e9+1;
int tot,mi[N*18],mx[N*18],lson[N*18],rson[N*18],tag[N*18];
int n,m;
inline void Chg(int x,int v){mi[x]+=v;mx[x]+=v;tag[x]+=v;}
int New_node(int l,int r)
{
tot++;mi[tot]=l;mx[tot]=r;
return tot;
}
inline void Pushdown(int u,int l,int r,int mid){
if (tag[u])
{
if (!lson[u]) lson[u]=New_node(l,mid);
if (!rson[u]) rson[u]=New_node(mid+1,r);
Chg(lson[u],tag[u]);
Chg(rson[u],tag[u]);
tag[u]=0;
}
}
inline void Up(int u,int l,int r,int mid)
{
mi[u]=min(!lson[u]?l:mi[lson[u]],!rson[u]?mid:mi[rson[u]]);
mx[u]=max(!lson[u]?mid+1:mx[rson[u]],!rson[u]?r:mx[rson[u]]);
}
void Upd(int &x,int l,int r,int ql,int qr,int val)
{
if(ql>qr) return;
if(!x) x=New_node(l,r);
if(ql<=l&&r<=qr)
{
Chg(x,val);
return;
}
int mid=l+r>>1;
Pushdown(x,l,r,mid);
if(ql<=mid) Upd(lson[x],l,mid,ql,qr,val);
if(qr>mid) Upd(rson[x],mid+1,r,ql,qr,val);
Up(x,l,r,mid);
}
int Get_l(int x,int l,int r,int v)
{
if((!x?l:mi[x])>=v) return -1;
if(l==r) return l;
int mid=l+r>>1;
Pushdown(x,l,r,mid);
int ret=Get_l(rson[x],mid+1,r,v);
if (ret!=-1) return ret;
return Get_l(lson[x],l,mid,v);
}
int Get_r(int x,int l,int r,int v)
{
if((!x?r:mx[x])<=v) return mo;
if(l==r) return l;
int mid=l+r>>1;
Pushdown(x,l,r,mid);
int ret=Get_r(lson[x],l,mid,v);
if (ret!=mo) return ret;
return Get_r(rson[x],mid+1,r,v);
}
int Que(int x,int l,int r,int que)
{
if(l==r) return !x?l:mi[x];
int mid=l+r>>1;
Pushdown(x,l,r,mid);
if(que<=mid) return Que(lson[x],l,mid,que);
else return Que(rson[x],mid+1,r,que);
}
ll las_ans;
int main()
{
n=read();
las_ans=0;
int maxn=1e9;
int rt=0;
For(i,1,n)
{
int x=read();
int l=Get_l(rt,0,maxn,x),r=Get_r(rt,0,maxn,x);
Upd(rt,0,maxn,0,l,1);Upd(rt,0,maxn,r,maxn,-1);
m=read();
For(i,1,m)
{
int x=(read()+las_ans)%mo;
las_ans=Que(rt,0,maxn,x);
writeln(las_ans);
}
}
}
聚聚快出CF757题解(期待(*❦ω❦)
补不动呜呜呜/(ㄒoㄒ)/~~