QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#777041 | #9249. Elimination Series Once More | guangxuautumn | WA | 1ms | 7896kb | C++14 | 1.7kb | 2024-11-23 22:25:33 | 2024-11-23 22:25:33 |
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()
{
ios::sync_with_stdio(0);
cin.tie(0);
// 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;
int q = query(l, r, 1, 1, n);
while(l < r) {
//大于x的数的个数=sum-query
// cout << i << ' ' << sum - query(l, r, 1, 1, n) << endl;
if(sum - q<= 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] << ' ';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7640kb
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
Wrong Answer
time: 0ms
memory: 7896kb
input:
3 5 2 4 7 5 3 8 6 1
output:
2 3 3 3 2 3 3 2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'