QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#218729 | #5035. foo~ | chenxinyang2006 | 10 | 34ms | 22348kb | C++14 | 3.5kb | 2023-10-18 17:42:55 | 2023-10-18 17:42:55 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int n,k;
int a[600005],b[600005],_pos[600005];
vector <int> sta;
vector <pii> Mx;
int f[600005],g[600005];
int fa[600005],_l[600005],_r[600005],val[600005],delta[600005];
int fnd(int u){
if(fa[u] == u) return u;
return fa[u] = fnd(fa[u]);
}
int answer,idx;
void push(int pos){
val[pos] = g[pos - 1];
// printf("PUSH %d %d\n",pos,val[pos]);
int u = fnd(pos - 1);
while(val[u] + delta[u] <= val[pos]){
int v = fnd(_l[u] - 1);
fa[u] = v;
delta[v] += delta[u];
_r[v] = _r[u];
u = v;
}
if(!_l[u]){
answer = val[pos];
idx = pos;
}
}
void add(int pos,int lim){//pos 后缀加 1
// printf("add %d\n",pos);
if(idx >= pos) answer++;
pos--;//[1,pos] 减 1
int u = fnd(pos),nxt = fnd(_r[u] + 1);
delta[u]++;
if(nxt > lim) return;
while(val[u] + delta[u] <= val[nxt]){
int v = fnd(_l[u] - 1);
fa[u] = v;
delta[v] += delta[u];
_r[v] = _r[u];
u = v;
}
if(!_l[u] && idx < nxt){
answer -= delta[u];
idx = _l[nxt];
}
}
void trans(){
val[0] = inf;
sta.clear();Mx.clear();
rep(i,1,n){
int cur = -inf;
while(!sta.empty() && a[i] > a[sta.back()]){
chkmax(cur,Mx.back().first);
sta.pop_back();
Mx.pop_back();
}
chkmax(cur,g[i - 1]);
if(!Mx.empty()) Mx.eb(mkp(cur,max(Mx.back().second,cur - SZ(sta))));
else Mx.eb(mkp(cur,cur));
sta.eb(i);
f[i] = Mx.back().second + SZ(sta);
}
// rep(i,1,n) printf("%d ",f[i]);
// printf("\n");
rep(i,1,n){
fa[i] = _l[i] = _r[i] = i;
delta[i] = 0;
}
answer = 0;
rep(i,1,n){
push(i);
add(_pos[i] + 1,i);
chkmax(f[i],answer);
// printf("curmax %d\n",answer);
}
rep(i,1,n) g[i] = f[i];
// printf("trans\n");
// rep(i,1,n) printf("%d ",g[i]);
// printf("\n");
}
int solve(){
// rep(i,1,n) printf("%d ",a[i]);
// printf("\n");
sta.clear();
g[0] = -inf;
rep(i,1,n){
while(!sta.empty() && a[i] > a[sta.back()]) sta.pop_back();
if(sta.empty()) _pos[i] = 0;
else _pos[i] = sta.back();
sta.eb(i);
g[i] = SZ(sta);
}
/* rep(i,1,n) printf("%d ",g[i]);
printf("\n");
printf("_pos:\n");
rep(i,1,n) printf("%d ",_pos[i]);
printf("\n");*/
rep(i,1,k - 1) trans();
int ans = 0;
rep(i,1,n) chkmax(ans,g[i]);
// printf("%d\n",ans);
return ans;
}
int main(){
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
scanf("%d%d",&n,&k);
int pos = -1;
rep(i,1,n){
scanf("%d",&b[i]);
if(b[i] == n) pos = i;
}
assert(pos != -1);
rep(i,pos,n) a[i - pos + 1] = b[i];
rep(i,1,pos - 1) a[n - pos + 1 + i] = b[i];
int ans = solve();
reverse(a + 2,a + n + 1);
printf("%d\n",max(ans,solve()));
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 22320kb
input:
23 6 16 20 22 4 21 10 3 7 5 8 15 12 9 1 6 17 23 13 11 19 18 14 2
output:
19
result:
wrong answer 1st words differ - expected: '20', found: '19'
Subtask #2:
score: 10
Accepted
Test #21:
score: 10
Accepted
time: 4ms
memory: 14072kb
input:
93943 1 87243 48984 50611 19218 77699 25025 85769 28141 13380 34875 42459 66419 53472 4367 48292 16894 92171 87263 42527 67085 30687 29235 27515 81053 31421 34864 83591 70491 75344 7026 50250 63402 26773 5330 36308 76399 80032 15501 16205 71750 73964 67876 68901 70548 2043 79979 89479 19784 38838 44...
output:
25
result:
ok "25"
Test #22:
score: 0
Accepted
time: 5ms
memory: 11956kb
input:
112118 1 24338 1586 3 108269 5 53472 80391 70331 9 15335 62487 28331 13 14 16564 94323 36681 108815 32632 44382 21 22 23 24 11758 40070 21518 51991 109983 30 45524 59784 33 2068 62111 36 37 38 39 89031 30508 42 43 16414 110006 34303 47 10331 44651 50 93957 95407 22019 88681 56605 12426 28498 58 59 8...
output:
281
result:
ok "281"
Test #23:
score: 0
Accepted
time: 27ms
memory: 16196kb
input:
391400 1 158965 280194 3 4 5 369036 92293 245923 57403 10 6887 280754 277300 110148 314164 135940 17 46573 126951 111447 301107 22 23 24 25 26 247952 28 342994 339309 23647 350245 33 299608 35 36 37 263236 232063 40 41 42 43 44 39280 46 299122 11961 380375 384513 51 318009 162567 54 55 56 27356 58 6...
output:
693
result:
ok "693"
Test #24:
score: 0
Accepted
time: 34ms
memory: 12908kb
input:
440571 1 243784 2 3 130039 61385 6 7 8 244611 260729 29014 12 326371 416098 15 293728 182717 66822 387603 156910 225815 413135 171756 315815 26444 302419 384825 37746 17634 391896 354575 426625 290920 34 49456 36 161212 212843 39 40 41 436888 43 102088 405279 46 47 77451 49 50 368530 52402 34143 54 ...
output:
665
result:
ok "665"
Test #25:
score: 0
Accepted
time: 15ms
memory: 14204kb
input:
237580 1 1 2 3 4 5 45736 171997 8 235046 10 11 186778 13 14 15 16 17 18 19 20 21 22 23 91724 25 147783 27 125261 29 30 27556 32 108919 76675 35 36 18966 212471 100584 11715 204252 77843 43 176763 18552 46 82644 48 49 50 51 191552 53 232631 160703 114013 69672 75193 59 60 207114 62 63 167312 83372 66...
output:
890
result:
ok "890"
Test #26:
score: 0
Accepted
time: 6ms
memory: 14080kb
input:
108629 1 1 2 3 35575 5 7205 104276 8 9 10 104552 12 13 99818 15 16 17 18 19 16579 21 74459 23 24 25 98758 27 30553 28622 105401 31 32 33 98277 29214 36 37 38 34671 99851 41 42 20159 65626 49334 58829 47 48 15553 50 16448 157 96610 71139 51449 24593 66195 11741 5738 45685 61 76006 91433 64 13205 66 6...
output:
549
result:
ok "549"
Test #27:
score: 0
Accepted
time: 2ms
memory: 12020kb
input:
7474 1 6087 2 3 3276 2246 1022 4790 8 9 10 11 3555 13 14 5187 16 17 18 5222 2852 21 3905 23 2069 25 26 27 6248 29 30 31 32 33 3467 35 5413 37 38 39 40 41 42 43 44 45 46 47 6366 6217 6683 4855 86 6754 7423 55 56 3421 58 7129 6415 2719 964 63 7191 6681 5871 2830 68 1114 70 71 4387 73 74 75 76 77 394 7...
output:
117
result:
ok "117"
Test #28:
score: 0
Accepted
time: 27ms
memory: 16072kb
input:
327474 1 210193 138271 6815 114087 210548 236834 247829 287541 142327 57519 226037 185228 4602 111639 172642 13926 122775 323427 276201 198051 175153 262523 182602 84772 315273 161585 146845 231049 98201 170526 58890 213780 86346 161912 320369 55154 202159 224318 92082 314469 92925 225630 89586 2190...
output:
31
result:
ok "31"
Test #29:
score: 0
Accepted
time: 12ms
memory: 14152kb
input:
170736 1 1312 68283 94512 153956 14227 44793 18760 153190 59267 3745 39898 34452 88526 153153 151245 72089 72230 139449 97869 105574 61308 52310 63909 66185 76461 57922 15750 32965 63821 123214 62562 154258 26229 154847 29694 20613 163634 112566 78733 77415 148297 8311 18695 146847 137996 128167 946...
output:
27
result:
ok "27"
Test #30:
score: 0
Accepted
time: 7ms
memory: 14156kb
input:
70972 1 42126 45376 26395 39090 6557 69493 22740 10263 3057 30503 16364 27796 52951 62922 17830 66723 34385 8039 28194 11087 10500 9835 5892 8917 21894 16673 49698 55082 66683 54472 60557 6953 739 65333 59825 23918 39644 59672 59765 31158 30188 37359 60653 64449 28747 7064 53759 15156 11687 33993 33...
output:
25
result:
ok "25"
Test #31:
score: 0
Accepted
time: 33ms
memory: 16416kb
input:
471980 1 315450 386066 223827 468592 231628 77257 181339 466496 85446 27241 269600 85959 141799 29249 162311 264524 137245 205794 349273 166576 131873 5521 368496 302373 19082 283842 82343 281817 25429 161084 307699 192224 143156 188759 279732 138312 341989 400389 280646 404120 362537 182646 194306 ...
output:
32
result:
ok "32"
Test #32:
score: 0
Accepted
time: 10ms
memory: 12456kb
input:
141837 1 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...
output:
141837
result:
ok "141837"
Test #33:
score: 0
Accepted
time: 4ms
memory: 12276kb
input:
48198 1 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 ...
output:
48198
result:
ok "48198"
Test #34:
score: 0
Accepted
time: 3ms
memory: 12164kb
input:
28730 1 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173...
output:
14366
result:
ok "14366"
Test #35:
score: 0
Accepted
time: 6ms
memory: 12104kb
input:
89450 1 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171 173...
output:
44726
result:
ok "44726"
Subtask #3:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 0ms
memory: 22348kb
input:
1992 25 144 612 1315 1966 1779 1773 1529 625 36 1849 1783 1441 1388 1558 1258 724 137 397 542 353 1162 1213 406 792 1317 882 994 298 1864 1969 103 449 508 1501 89 1721 195 778 657 222 1152 1780 613 743 1206 694 829 142 69 1973 1465 1343 655 1540 155 146 350 491 759 1695 1082 1357 1329 1745 232 1850 ...
output:
229
result:
wrong answer 1st words differ - expected: '237', found: '229'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
100%
Accepted
Dependency #5:
0%