QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#289558 | #7859. Bladestorm | ucup-team987 | WA | 1ms | 3484kb | C++20 | 5.5kb | 2023-12-23 18:31:44 | 2023-12-23 18:31:45 |
Judging History
answer
#include<iostream>
#include<cassert>
#include <algorithm>
#include <cassert>
#include <vector>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
int ceil_pow2(int n) {
int x = 0;
while ((1U << x) < (unsigned int)(n)) x++;
return x;
}
constexpr int bsf_constexpr(unsigned int n) {
int x = 0;
while (!(n & (1 << x))) x++;
return x;
}
int bsf(unsigned int n) {
#ifdef _MSC_VER
unsigned long index;
_BitScanForward(&index, n);
return index;
#else
return __builtin_ctz(n);
#endif
}
} // namespace internal
} // namespace atcoder
namespace atcoder {
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
public:
segtree() : segtree(0) {}
explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}
explicit segtree(const std::vector<S>& v) : _n(int(v.size())) {
log = internal::ceil_pow2(_n);
size = 1 << log;
d = std::vector<S>(2 * size, e());
for (int i = 0; i < _n; i++) d[size + i] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
void set(int p, S x) {
assert(0 <= p && p < _n);
p += size;
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) const {
assert(0 <= p && p < _n);
return d[p + size];
}
S prod(int l, int r) const {
assert(0 <= l && l <= r && r <= _n);
S sml = e(), smr = e();
l += size;
r += size;
while (l < r) {
if (l & 1) sml = op(sml, d[l++]);
if (r & 1) smr = op(d[--r], smr);
l >>= 1;
r >>= 1;
}
return op(sml, smr);
}
S all_prod() const { return d[1]; }
template <bool (*f)(S)> int max_right(int l) const {
return max_right(l, [](S x) { return f(x); });
}
template <class F> int max_right(int l, F f) const {
assert(0 <= l && l <= _n);
assert(f(e()));
if (l == _n) return _n;
l += size;
S sm = e();
do {
while (l % 2 == 0) l >>= 1;
if (!f(op(sm, d[l]))) {
while (l < size) {
l = (2 * l);
if (f(op(sm, d[l]))) {
sm = op(sm, d[l]);
l++;
}
}
return l - size;
}
sm = op(sm, d[l]);
l++;
} while ((l & -l) != l);
return _n;
}
template <bool (*f)(S)> int min_left(int r) const {
return min_left(r, [](S x) { return f(x); });
}
template <class F> int min_left(int r, F f) const {
assert(0 <= r && r <= _n);
assert(f(e()));
if (r == 0) return 0;
r += size;
S sm = e();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!f(op(d[r], sm))) {
while (r < size) {
r = (2 * r + 1);
if (f(op(d[r], sm))) {
sm = op(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(d[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
int _n, size, log;
std::vector<S> d;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};
} // namespace atcoder
using namespace std;
const int LIM=100;
struct dat{
bool ex;
int len;
pair<int,int>skip,dp[LIM];
};
int N,K;
dat op(dat l,dat r)
{
//dp
if(!r.ex)
{
for(int c=0;c<K;c++)l.dp[c].second-=r.len;
}
else
{
for(int c=0;c<K;c++)
{
int nc=l.dp[c].second;
if(nc>=0)l.dp[c].first+=r.dp[nc].first,l.dp[c].second=r.dp[nc].second;
else if(nc+K>r.len)l.dp[c].first+=r.dp[nc+K].first+1,l.dp[c].second=r.dp[nc+K].second;
else l.dp[c].first+=r.skip.first+1,l.dp[c].second=r.skip.second;
}
}
//skip
if(!l.ex)l.skip=r.skip;
else
{
int nc=l.skip.second;
if(nc>=0)l.skip.first+=r.dp[nc].first,l.skip.second=r.dp[nc].second;
else if(nc+K>r.len)l.skip.first+=r.dp[nc+K].first+1,l.skip.second=r.dp[nc+K].second;
else l.skip.first+=r.skip.first+1,l.skip.second=r.skip.second;
}
//len
if(!l.ex)l.len+=r.len;
//ex
l.ex=l.ex||r.ex;
return l;
}
dat EMPTY;
dat e(){return EMPTY;}
int A[1<<17];
int pr[2<<17];
int find(int u)
{
if(pr[u]!=u)pr[u]=find(pr[u]);
return pr[u];
}
int ans[1<<17];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
EMPTY.ex=false;
EMPTY.len=0;
for(int c=0;c<LIM;c++)EMPTY.dp[c]=make_pair(0,c);
int T;cin>>T;
for(;T--;)
{
cin>>N>>K;
for(int i=0;i<N;i++)cin>>A[i];
if(K>LIM)
{
for(int i=0;i<=N;i++)pr[i]=i;
for(int i=N+1;i<=N+K;i++)pr[i]=N+K;
pr[0]=1;
for(int i=N;i--;)
{
ans[i]=0;
int cur=0;
while(true)
{
int nxt=find(cur);
if(nxt>N)break;
ans[i]++;
if(nxt-cur<K)cur+=K;
else cur=nxt;
}
pr[A[i]]=find(A[i]+1);
}
}
else
{
dat EMP;
EMP.ex=false;
EMP.len=1;
for(int c=0;c<K;c++)EMP.dp[c]=make_pair(0,c-1);
atcoder::segtree<dat,op,e>seg(vector<dat>(N,EMP));
dat EX=EMP;
EX.ex=true;
EX.dp[0]=make_pair(1,K-1);
for(int i=0;i<N;i++)
{
seg.set(A[i]-1,EX);
dat t=seg.all_prod();
ans[i]=t.dp[0].first;
}
}
for(int i=0;i<N;i++)cout<<ans[i]<<(i+1==N?"\n":" ");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3484kb
input:
3 7 2 4 7 3 6 1 2 5 11 3 10 7 4 9 6 8 5 1 3 2 11 9 2 1 2 3 7 8 9 4 5 6
output:
1 2 3 3 4 4 4 2 3 4 3 3 3 3 4 4 4 4 1 1 2 3 4 4 4 5 5
result:
wrong answer 2nd lines differ - expected: '1 2 3 3 3 3 3 4 4 4 4', found: '2 3 4 3 3 3 3 4 4 4 4'