QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#777036 | #9249. Elimination Series Once More | guangxuautumn | TL | 1ms | 7668kb | C++14 | 1.7kb | 2024-11-23 22:24:16 | 2024-11-23 22:24:17 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int M = (1 << 20) + 10;
ll tree[M << 2];
ll pos[M];
ll ans[M];
ll ls(int p) {return p<<1;}
ll rs(int p) {return p<<1|1;}
void push_up(int p) {
tree[p] = tree[ls(p)] + tree[rs(p)];
}
void build(int p, int pl, int pr) {
if(pl == pr) {tree[p] = 0;return;}
int mid = (pl + pr) >> 1;
build(ls(p), pl, mid);
build(rs(p), mid + 1, pr);
push_up(p);
}
void update(int p, int pl, int pr, int po, int d)
{
if(pr < po || pl > po) return;
if(pl == pr) {tree[p] = d;return;}
int mid = (pl + pr) >> 1;
update(ls(p), pl, mid, po, d);
update(rs(p), mid + 1, pr, po, d);
push_up(p);
}
int query(int l, int r, int p, int pl, int pr)
{
if(l <= pl && pr <= r) return tree[p];
int mid = (pl + pr) >> 1;
int res = 0;
if(l <= mid) res += query(l, r, ls(p), pl, mid);
if(r > mid) res += query(l, r, rs(p), mid + 1, pr);
return res;
}
int main()
{
// cout << N;
int n, k;
cin >> n >> k;
int N = 1 << n;
vector<int> v(N + 1);
for(int i = 1; i <= N; i ++) {
cin >> v[i];
pos[v[i]] = i;//power为i的人的位置
}
build(1, 1, n);
for(int i = 1; i <= N; i ++) {
int l = 1, r = N, sum = N, t = n;
// cout << query(l, r, 1, 1, n) << endl;
while(l < r) {
//大于x的数的个数=sum-query
// cout << i << ' ' << sum - query(l, r, 1, 1, n) << endl;
if(sum - query(l, r, 1, 1, n) <= k) {
ans[pos[i]] = t;
break;
}
t --;
sum /= 2;
if(r / 2 > pos[i]) l = (r / 2) + 1;
else r = r / 2;
}
update(1, 1, N, pos[i], 1);
}
for(int i = 1; i <= N; i ++) cout << ans[i] << ' ';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7668kb
input:
2 1 1 2 3 4
output:
0 1 1 2
result:
ok 4 number(s): "0 1 1 2"
Test #2:
score: -100
Time Limit Exceeded
input:
3 5 2 4 7 5 3 8 6 1