QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#656235 | #9249. Elimination Series Once More | Fiatiustitia# | WA | 0ms | 3640kb | C++20 | 2.5kb | 2024-10-19 11:54:33 | 2024-10-19 11:54:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template <class T>
struct BIT
{
int n;
vector<T> val;
BIT(int _n) : n(_n), val(n) {}
uint32_t lowbit(uint32_t x) { return (x & -x); }
void update(int p, const T &w)
{
p++;
for (; p < n; p += lowbit(p))
val[p] += w;
}
T query(int p)
{
p++;
T res = 0;
for (; p; p -= lowbit(p))
res += val[p];
return res;
}
T query(int l, int r)
{
return query(r) - query(l - 1);
}
int lower_bound(const T &x)
{
static int bitn = 1;
while (bitn < n)
bitn <<= 1;
int p = 0;
T cur = 0;
for (int w = bitn; w; w /= 2)
{
if (p + w / 2 < n && cur + val[p + w / 2] <= x)
{
cur += val[p + w / 2];
p += w / 2;
}
}
return p;
}
};
void solve()
{
int n, k;
cin >> n >> k;
const int m = 1 << n;
BIT<int64_t> ST(m + 2);
vector bid(m, vector<int>(n + 1)), L(m, vector<int>(n + 1)), R(m, vector<int>(n + 1));
vector<int> ar(m), res(m), idx(m);
iota(idx.begin(), idx.end(), 0);
for (int i = 0; i < m; i++)
{
ST.update(i, 1);
cin >> ar[i];
for (int j = 0; j <= n; j++)
bid[i][j] = i / (1 << j);
}
for (int j = 0; j <= n; j++)
for (int i = 0; i < m; i++)
{
L[i][j] = i * (1 << j);
R[i][j] = (i + 1) * (1 << j) - 1;
}
sort(idx.begin(), idx.end(), [&](int a, int b)
{ return ar[a] < ar[b]; });
for (int i = 0; i < m; i++)
{
auto id = idx[i];
ST.update(id, -1);
int cur = min(k, ar[id] - 1);
for (int j = 0; j <= n; j++)
{
auto need = ST.query(L[bid[i][j]][j], R[bid[i][j]][j]);
if (need > cur)
{
res[id] = j - 1;
cur = 0;
break;
}
cur -= need;
}
if (cur > 0)
res[id] = n;
}
for (int i = 0; i < m; i++)
cout << res[i] << " \n"[i == m - 1];
}
int main()
{
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
auto _ = clock();
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
#ifdef LOCAL
cerr << clock() - _ << '\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
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: 3640kb
input:
3 5 2 4 7 5 3 8 6 1
output:
0 1 3 2 0 3 0 -1
result:
wrong answer 1st numbers differ - expected: '1', found: '0'