QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#299479 | #7859. Bladestorm | ucup-team134# | TL | 1247ms | 17448kb | C++14 | 2.6kb | 2024-01-06 21:33:55 | 2024-01-06 21:33:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=200050;
int p[N];
int Find(int x){return p[x]==x?x:p[x]=Find(p[x]);}
int ans[N],a[N];
void SolveBigK(int n,int k){
for(int i=0;i<=n+1;i++)p[i]=i;
for(int i=n;i>=1;i--){
int now=0;
ans[i]=0;
while(now<n){
int x=Find(now+1);
if(x==n+1)break;
now=max(x,now+k);
//printf("%i ",now);
ans[i]++;
}
//printf("\n");
p[a[i]]=a[i]+1;
}
}
vector<int> ls,rs;
int tsz,root;
vector<vector<pair<int,int>>> dp;
int b[N],k;
void BuildBlock(int c,int B){
int l=B*k+1;
int r=l+k-1;
if(dp[c].empty()){
dp[c].resize(2*k);
}
//printf("Block (%i %i)\n",l,r);
for(int st=-k;st<k;st++){
int now=l+st;
int fir=Find(max(now+1,l));
if(fir>r){
dp[c][st+k]={0,max(-k,now-(r+1))};
}else{
now=max(now+k,fir);
fir=Find(now+1);
if(fir>r){
dp[c][st+k]={1,now-(r+1)};
}else{
now=max(now+k,fir);
dp[c][st+k]={2,now-(r+1)};
}
}
//printf("dp[%i] = {%i, %i}\n",st,dp[c][st+k].first,dp[c][st+k].second);
}
}
void pull(int c){
if(dp[c].empty()){
dp[c].resize(2*k);
}
//printf("Merge %i %i -> %i\n",ls[c],rs[c],c);
for(int st=-k;st<k;st++){
int where=dp[ls[c]][st+k].second;
dp[c][st+k].first=dp[ls[c]][st+k].first+dp[rs[c]][where+k].first;
dp[c][st+k].second=dp[rs[c]][where+k].second;
//printf("dp[%i] = {%i, %i}\n",st,dp[c][st+k].first,dp[c][st+k].second);
}
}
void Build(int &c,int ss,int se){
c=++tsz;
if(ss==se){
BuildBlock(c,ss);
return;
}
int mid=ss+se>>1;
Build(ls[c],ss,mid);
Build(rs[c],mid+1,se);
pull(c);
}
void Upd(int c,int ss,int se,int qi){
if(ss==se){
BuildBlock(c,ss);
return;
}
int mid=ss+se>>1;
if(qi<=mid)Upd(ls[c],ss,mid,qi);
else Upd(rs[c],mid+1,se,qi);
pull(c);
}
void SolveSmallK(int n,int k){
::k=k;
for(int i=1;i<=n;i++)b[i]=1;
for(int i=0;i<=n;i++)p[i]=i;
for(int i=n+1;i<=n+k;i++)p[i]=i+1;
p[n+k+1]=n+k+1;
int mxb=(n-1)/k;
ls.resize(2*(mxb+1));
rs.resize(2*(mxb+1));
dp.resize(2*(mxb+1));
Build(root,0,mxb);
for(int i=n;i>=1;i--){
ans[i]=dp[root][k-1].first;
p[a[i]]=a[i]+1;
b[a[i]]=0;
//printf("Upd %i\n\n",a[i]);
Upd(root,0,mxb,(a[i]-1)/k);
}
ls.clear();
rs.clear();
dp.clear();
root=0;
tsz=0;
}
int main(){
int t;
scanf("%i",&t);
while(t--){
int n,k;
scanf("%i %i",&n,&k);
for(int i=1;i<=n;i++)scanf("%i",&a[i]);
if((ll)k*k>=n)SolveBigK(n,k);
else SolveSmallK(n,k);
for(int i=1;i<=n;i++)printf("%i ",ans[i]);
printf("\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3728kb
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 1 2 3 3 3 3 3 4 4 4 4 1 1 2 3 4 4 4 5 5
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 34ms
memory: 5820kb
input:
40319 1 1 1 2 1 1 2 2 1 2 1 2 2 1 2 2 2 2 1 3 1 1 2 3 3 1 1 3 2 3 1 2 1 3 3 1 2 3 1 3 1 3 1 2 3 1 3 2 1 3 2 1 2 3 3 2 1 3 2 3 2 2 1 3 3 2 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 1 1 1 1 1 1 1 1...
result:
ok 50000 lines
Test #4:
score: 0
Accepted
time: 110ms
memory: 5936kb
input:
5000 100 2 63 78 43 82 37 72 75 31 48 32 69 7 71 5 38 100 85 45 12 83 92 41 81 19 21 14 57 74 87 73 59 4 40 91 55 53 20 60 96 17 64 24 9 22 2 62 84 90 46 61 95 50 26 13 34 79 8 65 54 70 1 56 15 88 67 28 27 98 3 39 51 93 52 11 16 10 97 94 36 18 80 30 66 49 29 42 77 35 99 44 25 68 47 89 33 86 76 23 58...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 22 23 24 25 26 26 27 27 28 29 29 30 31 32 32 33 34 35 36 37 38 39 40 40 40 40 41 41 42 43 44 44 45 46 46 46 46 46 46 46 46 46 47 48 48 49 49 49 49 49 49 49 49 49 49 49 49 49 49 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 1 2 3 4 ...
result:
ok 5000 lines
Test #5:
score: 0
Accepted
time: 121ms
memory: 5932kb
input:
5000 100 3 23 52 62 18 85 78 19 65 26 46 100 33 57 32 3 13 12 16 81 75 72 2 92 22 80 95 60 45 94 24 43 73 67 35 77 15 25 47 56 28 48 36 10 59 93 27 9 34 54 58 55 91 87 31 76 42 11 68 96 97 89 83 79 74 20 8 7 70 38 84 6 64 63 99 53 98 49 66 90 30 69 40 50 61 37 1 39 29 5 4 82 44 41 86 51 14 21 88 17 ...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 17 18 19 20 20 21 21 21 22 23 24 24 24 24 24 25 25 25 25 25 26 26 27 27 27 28 28 28 28 28 28 28 28 28 29 30 30 30 30 30 31 31 31 31 31 31 31 31 32 32 32 33 33 33 33 33 33 33 33 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 1 2 3 4 ...
result:
ok 5000 lines
Test #6:
score: 0
Accepted
time: 183ms
memory: 5932kb
input:
5000 100 8 69 26 68 33 32 41 79 80 22 43 94 31 87 15 7 11 25 4 28 12 13 19 83 48 40 60 76 58 34 81 93 10 55 37 3 59 71 89 49 52 21 82 2 85 84 62 16 45 57 36 39 51 95 50 70 30 42 47 77 64 23 88 1 91 63 61 97 73 67 9 99 53 100 54 18 29 96 72 75 35 98 56 92 46 6 27 65 74 20 86 14 38 78 44 17 66 90 5 8 ...
output:
1 2 3 4 4 5 6 6 7 7 8 8 9 10 11 11 11 11 11 11 11 11 11 11 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 1 2 3 4 5 6 ...
result:
ok 5000 lines
Test #7:
score: 0
Accepted
time: 63ms
memory: 3896kb
input:
5000 100 8 66 22 6 89 68 15 82 100 62 26 43 79 76 47 32 25 27 33 50 75 77 92 42 40 11 81 54 31 28 7 87 58 96 45 21 91 97 98 13 86 69 19 10 61 72 44 36 24 51 64 55 14 34 46 2 65 59 41 17 5 74 18 57 20 94 3 90 88 78 12 93 8 48 85 37 80 95 9 71 52 83 35 73 56 60 84 39 30 16 49 38 23 1 70 4 53 29 99 63 ...
output:
1 2 3 4 5 6 7 8 8 9 10 11 11 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 1 2 3 4 5...
result:
ok 5000 lines
Test #8:
score: 0
Accepted
time: 46ms
memory: 3808kb
input:
5000 100 8 25 36 39 50 79 40 3 19 91 97 72 6 62 54 33 66 78 26 45 13 43 12 95 94 89 17 70 41 65 52 4 5 21 90 82 68 67 63 83 11 99 57 84 85 98 1 87 74 14 35 31 37 10 30 80 81 60 88 56 32 86 96 53 61 58 71 38 48 55 44 8 24 64 75 9 22 93 34 2 47 100 46 15 23 73 28 76 16 29 49 7 18 51 92 59 77 42 69 20 ...
output:
1 2 3 4 5 5 6 7 8 9 10 10 11 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 1 2 2 3 3...
result:
ok 5000 lines
Test #9:
score: 0
Accepted
time: 78ms
memory: 6288kb
input:
50 10000 8 274 974 424 4088 762 1098 5354 5693 8734 243 1673 3993 972 5992 9422 4459 6504 4367 7594 9625 4021 7371 3760 1834 2602 5886 2573 5608 2338 5869 6036 4523 5430 9915 5902 979 6434 6013 8881 9136 7450 6065 9790 9051 9545 9938 8604 7526 5829 2766 1433 6053 9650 1712 5928 9002 3854 1152 2778 1...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 1...
result:
ok 50 lines
Test #10:
score: 0
Accepted
time: 262ms
memory: 17448kb
input:
5 100000 1 98420 62278 61893 21653 60003 72714 31478 93221 52310 28889 69896 3599 74920 72182 84226 27631 5337 74459 11956 99033 59122 23980 95516 12262 88093 55256 85020 35044 18848 86156 81566 44214 73514 22994 25629 83306 81401 39189 88840 6980 69761 54464 55186 76771 43620 59242 72845 61388 8089...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok 5 lines
Test #11:
score: 0
Accepted
time: 266ms
memory: 13572kb
input:
5 100000 2 64399 63674 21280 16692 49293 81297 84388 39242 34119 80513 17260 59983 26842 94045 2753 90512 76105 17987 34265 70348 71403 14911 70011 10600 40925 98037 90705 27361 4364 50825 57345 18247 50196 5511 48862 32797 91905 80229 20782 37621 98115 90270 82476 87164 21970 2281 24796 30439 22752...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok 5 lines
Test #12:
score: 0
Accepted
time: 406ms
memory: 9152kb
input:
5 100000 8 76194 71588 27212 86287 69258 56624 74892 60254 94291 64851 31220 38875 48689 5689 19483 783 91032 21265 71981 9390 12949 95047 80129 11912 8898 32471 80931 40552 30401 12358 1934 9916 15511 55750 69816 78633 20401 93320 27466 66319 58076 48154 96212 17882 83673 81027 12602 21517 35704 72...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok 5 lines
Test #13:
score: 0
Accepted
time: 1247ms
memory: 9972kb
input:
5 100000 8 3405 68273 96596 86470 49252 63887 24398 4672 37187 52435 64116 60894 44120 174 56748 45679 79691 42923 96599 22730 44310 4403 27462 85208 80277 4743 31252 67178 13357 33995 96056 99917 48186 18377 68417 90737 89033 53482 24664 63539 94248 14199 39211 91709 95405 80931 49139 42635 85614 4...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 ...
result:
ok 5 lines
Test #14:
score: -100
Time Limit Exceeded
input:
5 100000 200 50573 49627 37560 74624 24741 5634 18355 52180 80358 20343 3290 67242 53105 69545 58400 63857 1919 83527 91130 5971 87369 14265 38136 22901 24675 63793 72964 10635 95913 38437 92826 7577 51476 51296 17582 25422 33321 67027 94755 85748 85877 1500 38644 23051 23500 5436 54539 53497 36574 ...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 61 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...