QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#61845 | #4500. Loop | qinjianbin | AC ✓ | 368ms | 22992kb | C++14 | 1.6kb | 2022-11-15 16:09:45 | 2022-11-15 16:09:48 |
Judging History
answer
#include<cstdio>
#include<set>
#include<iostream>
#define mid ((l+r)>>1)
#define lx (x<<1)
#define rx (x<<1|1)
using namespace std;
const int maxn =300000+5;
int n,m;
int a[maxn],b[maxn];
bool flag[maxn];
int st[maxn<<2];
void build_st(int x,int l,int r)
{
if (l==r)
{
st[x]=l;
}else {
build_st(lx,l,mid);
build_st(rx,mid+1,r);
if (a[st[lx]]<a[st[rx]]) st[x]=st[rx];
else st[x]=st[lx];
}
}
int max_st(int x,int l,int r,int L,int R)
{
if (r<L||l>R) return 0;
if (l>=L&&r<=R) return st[x];
int tL=max_st(lx,l,mid,L,R);
int tR=max_st(rx,mid+1,r,L,R);
if (tL==0||tR==0) return tL+tR;
if (a[tL]<a[tR]) return tR;
else return tL;
}
void standing_by()
{
int i;
int L,R;
int mx;
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++) scanf("%d",&a[i]),flag[i]=false;
build_st(1,1,n);
for(L=1;L<=n;L=R)
{
mx=max_st(1,1,n,L,L+m);
flag[mx]=true;
R=mx+1;
m-=(mx-L);
}
//for(i=1;i<=n;i++) printf("%d ",flag[i]);
//puts("");
}
multiset<int> qhy;
void complete()
{
int i;
qhy.clear();
for(i=1;i<=n;i++)
{
if (flag[i])
{
while (!qhy.empty())
{
auto it=qhy.end();
it--;
if (*it<=a[i]) break;
printf("%d ",*it);
qhy.erase(it);
}
printf("%d ",a[i]);
}else qhy.insert(a[i]);
}
if (!qhy.empty())
{
auto it=qhy.end();
it--;
while (1)
{
printf("%d ",*it);
if (it==qhy.begin()) break;
it--;
}
}
puts("");
}
int main()
{
int t=1;
scanf("%d",&t);
for(;t;t--)
{
standing_by();
complete();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 368ms
memory: 22992kb
input:
100 300000 300000 1 1 300000 153456 153456 1 153456 153456 300000 1 300000 1 300000 300000 300000 1 300000 300000 300000 1 300000 300000 300000 300000 300000 1 300000 153456 300000 1 153456 153456 1 300000 153456 300000 300000 1 300000 1 1 153456 153456 300000 153456 153456 153456 153456 1 300000 30...
output:
300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000 300000...
result:
ok 100 lines