QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#693136#9249. Elimination Series Once MoreCore_65536#WA 1ms7804kbC++237.2kb2024-10-31 15:36:152024-10-31 15:36:16

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 15:36:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7804kb
  • [2024-10-31 15:36:15]
  • 提交

answer

/*
潩?潩潩潩?潩潩
	潩潩?潩潩i潩?濙�??潩?潩潩潩�?�?潩?�?濄�?潩�?潩潩[L, R]�?潩�?潩?潩?
	潩?潩潩[L, R]�?滾?潩?�?潩?潩潩潩潩�?潩潩ask潩潩潩?潩
	潩潩?潩潩�?潩潩潩?潩�?漅潩�?�?�?潩L?潩潩�?潩?潩�?潩�?(L - 1)潩�?�
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
const int inf = 1 << 30;
struct ZXTree
{
	static const int maxn = 5000100;
	struct node
	{
		int l, r, v; //潩?潩� �??潩� ?
	} T[maxn * 25];
	int n, sz, root[maxn], data[maxn]; //n潩?潩�?潩潩?潩�
	void ins(int &i, int l, int r, int p) //潩潩潩[l, r]�?潩漰 
	{
		int m = (l + r) / 2;
		T[++sz] = T[i]; i = sz;
		T[i].v++; //潩潩潩?潩潩潩?�?潩� 
		if (l == r) return;
		if (p <= m) ins(T[i].l, l, m, p);
		else ins(T[i].r, m + 1, r, p);
	}
	int rank(int v)
	{
		//潩潩潩�?潩潩潩?潩?潩return v潩�?�??潩?潩潩�?漝ata[v]潩?v潩潩?潩?潩潩?潩?[1, n]潩
		return lower_bound(data + 1, data + n + 1, v) - data;
	}
	void init(int *A, int length) //潩潩潩潩A潩澅潩1潩?潩length潩?A�?潩�
	{
		root[0] = sz = 0;
		copy(A + 1, A + length + 1, data + 1);
		sort(data + 1, data + length + 1); //潩濢潩潩?潩潩?潩n潩�?�?潩?潩潩?潩潩?潩
		this->n = unique(data + 1, data + length + 1) - data - 1; //潩data潩潩潩潩潩�?潩
		for (int i = 1; i <= length; ++i) //潩�?�?潩潩潩�潩?濙潩潩潩潩?�??麧�?潩潩�
			ins(root[i] = root[i - 1], 1, n, rank(A[i])); //潩潩rank[i]潩潩濢�?滱潩潩潩潩�?潩潩�?�?�?潩滱[i]潩�?� 
														  //root[i]潩?潩A[1]潩A[i]潩潩潩?潩潩潩??�?潩潩�
	}
	int kth(int x, int y, int k)  //潩??潩潩潩潩潩[x, y]�??漦?潩?潩潩漦潩潩潩�?�??潩潩??潩潩潩 
	{
		int l = 1, r = n;
		x = root[x - 1], y = root[y];
		while (l < r)
		{
			int m = (l + r) / 2, t = T[T[y].l].v - T[T[x].l].v;
			if (k <= t)
				x = T[x].l, y = T[y].l, r = m;
			else
				x = T[x].r, y = T[y].r, l = m + 1, k -= t;
		}
		return data[r];
	}
	int ask(int x, int y, int v) //潩??潩潩潩潩潩[x, y]�?漹?潩?�?潩� 
	{
		int l = 1, r = n, k = 0;
		x = root[x - 1], y = root[y];
		int p = rank(v) - 1;
		if (p <= 0) return 0;
		while (l < r)
		{
			int m = (l + r) / 2, t = T[T[y].l].v - T[T[x].l].v;
			if (p <= m)
				x = T[x].l, y = T[y].l, r = m;
			else
				x = T[x].r, y = T[y].r, l = m + 1, k += t;
		}
		k += T[y].v - T[x].v;
		return k;
	}
	int pre(int x, int y, int l, int r, int p)
	{
		int m = (l + r) / 2, v = T[y].v - T[x].v;
		if (l == r) return v > 0 ? data[r] : -inf;
		int t = T[T[y].r].v - T[T[x].r].v;
		if (p <= m || t == 0) return pre(T[x].l, T[y].l, l, m, p); //潩漰潩�?潩潩潩潩潩潩潩?�?潩�?潩潩潩潩潩潩潩 
		int k = pre(T[x].r, T[y].r, m + 1, r, p);
		if (k != -inf) return k;
		return pre(T[x].l, T[y].l, l, m, p);
	}
	int pre(int x, int y, int v) //潩潩潩[x, y]�?�?v潩?潩潩�?潩潩潩�-inf
	{
		int p = rank(v) - 1;
		if (p <= 0) return -inf;
		return pre(root[x - 1], root[y], 1, n, p);
	}
	int pre2(int x, int y, int v) //潩潩潩[x, y]�?�?v潩?潩潩�?潩潩潩�-inf
	{
		int k = ask(x, y, v);
		if (k == 0) return -inf;
		return kth(x, y, k);
	}
	int next(int x, int y, int l, int r, int p)
	{
		int m = (l + r) / 2, v = T[y].v - T[x].v;
		if (l == r) return v > 0 ? data[r] : inf;
		int t = T[T[y].l].v - T[T[x].l].v;
		if (p > m || t == 0) return next(T[x].r, T[y].r, m + 1, r, p);
		int k = next(T[x].l, T[y].l, l, m, p);
		if (k != inf) return k;
		return next(T[x].r, T[y].r, m + 1, r, p);
	}
	int next(int x, int y, int v) //潩潩潩[x, y]�?�?v�?�?潩?潩潩潩漣nf
	{
		int p = rank(v + 1);
		if (p > n) return inf;
		return next(root[x - 1], root[y], 1, n, p);
	}
	int next2(int x, int y, int v) //潩潩潩[x, y]�?�?v�?�?潩?潩潩潩漣nf
	{
		int k = ask(x, y, v + 1) + 1;
		if (k > y - x + 1) return inf;
		return kth(x, y, k);
	}
	int count(int x, int y, int v)	//潩潩潩潩[x, y]潩v�?潩�
	{
		int l = 1, r = n;
		x = root[x - 1], y = root[y];
		int p = rank(v);
		if (p > n || data[p] != v)
			return 0;
		while (l < r && T[y].v - T[x].v > 0)
		{
			int m = (l + r) / 2;
			if (p <= m)
				x = T[x].l, y = T[y].l, r = m;
			else
				x = T[x].r, y = T[y].r, l = m + 1;
		}
		return T[y].v - T[x].v;
	}
	bool find(int x, int y, int v)	//潩??潩潩潩潩漑x, y]潩�?潩�?潩v
	{
		return count(x, y, v) >= 1;
	}
}zxtree;

const int maxn = 2000000;
int A[maxn], n, q;

void solve(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=(1<<n);i++){
        cin>>A[i];
    }
    zxtree.init(A,(1<<n));
    for(int i=1;i<=(1<<n);i++){
        int ans=0;
        if(A[i]==1){
            cout<<0<<" ";
            continue;
        }else if(A[i]==(1<<n)){
            cout<<n<<" ";
            continue;
        }
        auto check=[&](int j){
            int left=(i-1)/(1<<j)*(1<<j)+1;
            int right=(i-1)/(1<<j)*(1<<j)+(1<<j);
            int l=1;
            int r=(1<<j)+1;
            while(l<r){
                int mid=(l+r)/2;
                if(zxtree.kth(left,right,mid)<=A[i]){
                    l=mid+1;
                }else{
                    r=mid;
                }
            }
            int cnt=l;
            int res=A[i]-1-(cnt-1);
            int k1=min(k,res);
            if(k1+cnt-1>=(1<<j)-1){
                return 1;
            }else{
                return 0;
            }
        };
        int l1=1,r1=n;
        while(l1<r1){
            int mid=(l1+r1)/2;
            if(check(mid)==1){
                l1=mid+1;
            }else{
                r1=mid;
            }
        }
        ans=l1-1;
        cout<<ans<<" ";
        // for(int j=1;j<n;j++){
        //     int left=(i-1)/(1<<j)*(1<<j)+1;
        //     int right=(i-1)/(1<<j)*(1<<j)+(1<<j);
        //     // cout<<left<<" "<<right<<endl;
        //     // if(k>=(1<<j)-1){
        //     //     ans=j;
        //     //     continue;
        //     // }
        //     int l=1;
        //     int r=(1<<j)+1;
        //     while(l<r){
        //         int mid=(l+r)/2;
        //         if(zxtree.kth(left,right,mid)<A[i]){
        //             l=mid+1;
        //         }else{
        //             r=mid;
        //         }
        //     }
        //     int cnt=l;
        //     int res=A[i]-1-(cnt-1);
        //     int k1=min(k,res);
        //     if(k1+cnt-1>=(1<<j)-1){
        //         ans=j;
        //         continue;
        //     }else{
        //         break;
        //     }
        //     // int st=zxtree.kth(left,right,(1<<j)-k);
        //     // if(st<=A[i]){
        //     //     ans=j;
        //     // }else{
        //     //     break;
        //     // }
        // }
        // cout<<ans<<" ";
        // cout<<endl;
    }
    cout<<endl;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    while(t--){
        solve();
    }

	return 0;
}















Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7664kb

input:

2 1
1 2 3 4

output:

0 1 1 2 

result:

ok 4 number(s): "0 1 1 2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 7804kb

input:

3 5
2 4 7 5 3 8 6 1

output:

1 2 2 2 1 3 2 0 

result:

ok 8 numbers

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 7736kb

input:

3 0
1 2 7 4 5 8 3 6

output:

0 1 2 2 1 3 1 2 

result:

wrong answer 4th numbers differ - expected: '0', found: '2'