ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#200905 | #3478. select | Josephcheng | 100 | 472ms | 21656kb | C++ | 1.2kb | 2024-01-14 10:40:59 | 2024-01-14 12:18:10 |
answer
#include<bits/stdc++.h>
#define MAXN 1000005
#define LL long long
using namespace std;
int n,k,head=1,tail,pos;
int a[MAXN],nxt[MAXN],pre[MAXN],ans[MAXN],to[MAXN];
bool cmp[MAXN];
inline int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+(ch^48);
ch=getchar();
}
return x*f;
}
void remove(int st,int idx,int tmp,bool op)
{
if(tmp>k) return ;
// printf("%d %d %d\n",st,idx,tmp);
ans[st]=idx;
cmp[a[st]]=false;
if(head==st) head=nxt[st];
if(tail==st) tail=pre[st];
nxt[pre[st]]=nxt[st];
pre[nxt[st]]=pre[st];
if(tmp==0){
remove(pre[st],idx,tmp+1,0);
remove(nxt[st],idx,tmp+1,1);
return ;
}else{
if(op==0) remove(pre[st],idx,tmp+1,0);
if(op==1) remove(nxt[st],idx,tmp+1,1);
return ;
}
}
int main()
{
n=read();k=read();
for(int i=1;i<=n;i++)
a[i]=read(),nxt[i]=i+1,pre[i]=i-1,cmp[i]=true,to[a[i]]=i;
pre[1]=n,nxt[n]=1,pos=n;
head=1,tail=n;
for(int p=1;p<=n/(2*k+1)+(n%(2*k+1)!=0);p++){
while(!cmp[pos]) pos--;
remove(to[pos],p,0,0);
}
for(int i=1;i<=n;i++)
printf("%d ",ans[i]);
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1180kb
input:
500 5 393 398 108 117 84 445 14 451 142 53 50 449 491 196 365 488 303 46 429 300 57 348 189 141 293 ...
output:
28 28 28 28 32 32 32 9 9 9 9 9 9 9 9 9 9 9 32 32 32 32 45 29 29 29 29 29 3 3 3 3 3 3 3 3 3 3 3 29 29...
result:
ok single line: '28 28 28 28 32 32 32 9 9 9 9 9... 32 32 32 28 28 28 28 28 28 28 '
Test #2:
score: 10
Accepted
time: 0ms
memory: 1184kb
input:
800 4 732 529 460 536 20 397 470 705 723 571 471 95 578 613 582 522 734 312 751 631 260 510 170 72 4...
output:
50 50 50 50 50 54 54 54 54 54 54 54 54 82 39 39 39 39 39 39 39 39 39 82 82 82 82 86 86 86 25 25 25 2...
result:
ok single line: '50 50 50 50 50 54 54 54 54 54 ... 48 48 48 48 48 48 50 50 50 50 '
Test #3:
score: 10
Accepted
time: 0ms
memory: 1192kb
input:
999 11 425 709 285 798 610 394 18 777 62 828 101 891 726 204 19 609 933 655 812 593 819 668 651 201 ...
output:
35 35 35 35 41 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 41 41 25 25 25 2...
result:
ok single line: '35 35 35 35 41 36 36 36 36 36 ...3 3 3 3 3 3 3 3 26 26 31 31 35 '
Test #4:
score: 10
Accepted
time: 1ms
memory: 1372kb
input:
10000 15 2086 7229 9314 8859 8892 6883 9696 6205 6211 9028 4238 3319 4458 628 6552 9063 6006 6262 52...
output:
98 98 98 98 98 98 98 98 98 98 98 98 291 291 291 291 291 291 31 31 31 31 31 31 31 31 31 31 31 31 31 3...
result:
ok single line: '98 98 98 98 98 98 98 98 98 98 ... 98 98 98 98 98 98 98 98 98 98 '
Test #5:
score: 10
Accepted
time: 2ms
memory: 2200kb
input:
50000 98 7734 8076 7492 15131 23605 19303 36490 48940 27537 48475 38921 45541 43382 17930 48109 2583...
output:
18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 1...
result:
ok single line: '18 18 18 18 18 18 18 18 18 18 ... 18 18 18 18 18 18 18 18 18 18 '
Test #6:
score: 10
Accepted
time: 14ms
memory: 3216kb
input:
100000 76 96269 74627 80621 86094 91844 92348 99721 7372 26125 85969 94067 76051 63209 71619 39296 7...
output:
78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 4...
result:
ok single line: '78 78 78 78 78 78 78 78 78 78 ... 78 78 78 78 78 78 78 78 78 78 '
Test #7:
score: 10
Accepted
time: 80ms
memory: 11424kb
input:
500000 207 371252 499715 480852 496545 461421 476775 450423 491323 479946 497396 497165 485618 47794...
output:
66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 66 6...
result:
ok single line: '66 66 66 66 66 66 66 66 66 66 ... 66 66 66 66 66 66 66 66 66 66 '
Test #8:
score: 10
Accepted
time: 111ms
memory: 17576kb
input:
800000 425 785370 745167 785362 737709 718450 769221 792379 760938 796936 732010 796002 717915 79418...
output:
14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 1...
result:
ok single line: '14 14 14 14 14 14 14 14 14 14 ... 14 14 14 14 14 14 14 14 14 14 '
Test #9:
score: 10
Accepted
time: 132ms
memory: 21656kb
input:
999999 444 954211 992764 974842 986560 968768 992439 995281 999962 970289 975438 982780 985393 99697...
output:
25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 2...
result:
ok single line: '25 25 25 25 25 25 25 25 25 25 ... 25 25 25 25 25 25 25 25 25 25 '
Test #10:
score: 10
Accepted
time: 132ms
memory: 21652kb
input:
1000000 277 956112 974080 948497 979521 952353 962692 955605 995542 989620 978231 998101 985593 9998...
output:
55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 5...
result:
ok single line: '55 55 55 55 55 55 55 55 55 55 ... 55 55 55 55 55 55 55 55 55 55 '