#include<iostream> #include<cstdio> #include<cstring> #define N 262144 using namespace std; struct btree { int l,r,len; }; btree tree[N*3]; void buildtree(int p,int left,int right) { int w,mid; tree[p].l=left; tree[p].r=right; tree[p].len=right-left+1; if(left==right) return ; mid=(left+right)>>1; w=p<<1; buildtree(w,left,mid); buildtree(w+1,mid+1,right); } int query(int p,int k) { int w; tree[p].len--; if(tree[p].l==tree[p].r) return tree[p].l; w=p<<1; if(tree[w].len>=k) return query(w,k); else return query(w+1,k-tree[w].len); } int main() { int t; scanf("%d",&t); int i,n,k; long long sum; for(i=1;i<=t;i++) { scanf("%d %d",&n,&k); buildtree(1,1,n); int j; sum=0; for(j=0;j<k;j++) { int ww; scanf("%d",&ww); sum+=query(1,ww); } printf("Case %d: ",i); printf("%I64d\n",sum); //不知道为什么%lld就不对了额~ 对着人家的代码一个一个的找~~~~ } return 0; }