1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| #include<bits/stdc++.h> using namespace std; #define mod 1e9+7 #define ll long long const int M = 2e5+7; ll int a[M],number[M<<2],bz[M<<2]; int number2[M<<2],bz2[M<<2],to[M]; struct node{ int id; ll b; } no[M];
bool cmp(node a,node b){ return a.b==b.b ? a.id<b.id : a.b<b.b; }
void PushUp(int rt){ number[rt] = max(number[rt<<1],number[rt<<1|1]); }
void build(int l,int r,int rt){ bz[rt]=bz2[rt]=number[rt]=0; if(l==r){number2[rt]=0;return;} int mid = (l+r)>>1; build(l,mid,rt<<1); build(mid+1,r,rt<<1|1); PushUp(rt); }
void pushdown(int l,int r,int rt){ if(bz[rt]){ bz[rt<<1] += bz[rt]; bz[rt<<1|1] += bz[rt]; number[rt<<1] += bz[rt]; number[rt<<1|1] += bz[rt]; bz[rt] = 0; } if(bz2[rt]){ bz2[rt<<1] += bz2[rt]; bz2[rt<<1|1] += bz2[rt]; number2[rt<<1] += bz2[rt]; number2[rt<<1|1] += bz2[rt]; bz2[rt] = 0; } }
void change(ll o,int L,int R,int l,int r,int rt){ if(L>R) return; if(l==r){ number[rt]+=o; number2[rt]+=1; return ; } if(L<=l && r<=R){ number[rt]+=o; bz[rt]+=o; bz2[rt] += 1; return ; } int mid = (l+r)>>1; pushdown(l,r,rt); if(L<=mid) change(o,L,R,l,mid,rt<<1); if(R>mid) change(o,L,R,mid+1,r,rt<<1|1); PushUp(rt); }
ll query(ll k,int l,int r,int rt){ if(l==r) return number2[rt]; int mid = (l+r)>>1; pushdown(l,r,rt); int ans; if(k < number[rt<<1]) ans = query(k,l,mid,rt<<1); else ans = query(k,mid+1,r,rt<<1|1); PushUp(rt); return ans; }
int main(){ int t; scanf("%d",&t); while(t--){ int n,m; scanf("%d%d",&n,&m); build(1,n+1,1); for(int i=1;i<=n;i++){ scanf("%lld",&a[i]); no[i].b = a[i]; no[i].id = i; } sort(no+1,no+n+1,cmp);
change(1e9,n+1,n+1,1,n+1,1); for(int i=1;i<=n;i++) to[no[i].id] = i; for(int i=1;i<=n;i++){ ll k = query(m-a[i],1,n+1,1); printf("%lld ",i-k);
change(a[i],to[i],n+1,1,n+1,1); } puts(""); } return 0; }
|