QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85572 | #5035. foo~ | Reanap | 0 | 17ms | 17156kb | C++14 | 2.5kb | 2023-03-07 21:19:27 | 2023-03-07 21:21:21 |
Judging History
answer
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <iostream>
#include <algorithm>
#define pii pair <int , int>
#define pll pair <LL , LL>
#define mp make_pair
#define fs first
#define sc second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
//const int Mxdt=100000;
//static char buf[Mxdt],*p1=buf,*p2=buf;
//#define getchar() p1==p2&&(p2=(p1=buf)+fread(buf,1,Mxdt,stdin),p1==p2)?EOF:*p1++;
template <typename T>
void read(T &x) {
T f=1;x=0;char s=getchar();
while(s<'0'||s>'9') {if(s=='-') f=-1;s=getchar();}
while(s>='0'&&s<='9') {x=(x<<3)+(x<<1)+(s^'0');s=getchar();}
x *= f;
}
template <typename T>
void write(T x , char s='\n') {
if(!x) {putchar('0');putchar(s);return;}
if(x<0) {putchar('-');x=-x;}
T t = 0 , tmp[25] = {};
while(x) tmp[t ++] = x % 10 , x /= 10;
while(t -- > 0) putchar(tmp[t] + '0');
putchar(s);
}
const int MAXN = 6e5 + 5;
int f[2][MAXN] , g[2][MAXN] , h[MAXN] , a[MAXN << 1] , b[MAXN];
int n , k , las[MAXN] , nxt[MAXN] , sta[MAXN] , top;
/*
f pre
g suf
*/
int solve() {
sta[0] = n + 1;top = 0;
for (int i = n; i >= 1; --i) {
while(top && b[sta[top]] < b[i]) top --;
sta[++top] = i;
nxt[i] = sta[top - 1];
}
sta[0] = 0;
top = 0;
for (int i = 1; i <= n; ++i) {
while(top && b[sta[top]] < b[i]) top --;
sta[++top] = i;
las[i] = sta[top - 1];
}
int ans = 0;
for (int j = 1; j <= k; ++j) {
g[j & 1][0] = -1e9;
for (int i = 1; i <= n; ++i) {
g[j & 1][i] = max(g[j & 1][las[i]] + 1 , 1 + h[i - 1]);
f[j & 1][i] = max(f[j & 1][i] , max(g[(j - 1) & 1][i - 1] , f[(j - 1) & 1][i - 1]));
f[j & 1][nxt[i]] = max(f[j & 1][nxt[i]] , f[j & 1][i] + 1);
h[i] = max(h[i - 1] , max(g[(j - 1) & 1][i] , f[(j - 1) & 1][i]));
ans = max(ans , max(f[j & 1][i] , g[j & 1][i]));
}
memset(f[(j - 1) & 1] , 0 , sizeof f[(j - 1) & 1]);
memset(g[(j - 1) & 1] , 0 , sizeof g[(j - 1) & 1]);
memset(h , 0 , sizeof h);
}
memset(f[k & 1] , 0 , sizeof f[k & 1]);
memset(g[k & 1] , 0 , sizeof g[k & 1]);
memset(h , 0 , sizeof h);
return ans;
}
int main() {
read(n),read(k);
for (int i = 1; i <= n; ++i) read(a[i]) , a[i + n] = a[i];
int p = 1;
for (int i = 1; i <= n; ++i) if(a[i] == n) {
p = i;
}
for (int i = 1; i <= n; ++i) b[i] = a[p + i - 1];
int ans = solve();
for (int i = 1; i <= n; ++i) b[i] = a[p + i];
ans = max(ans , solve());
write(ans);
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: 8ms
memory: 15124kb
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:
18
result:
wrong answer 1st words differ - expected: '20', found: '18'
Subtask #2:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 14ms
memory: 17156kb
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:
24
result:
wrong answer 1st words differ - expected: '25', found: '24'
Subtask #3:
score: 0
Wrong Answer
Test #36:
score: 0
Wrong Answer
time: 17ms
memory: 15164kb
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:
228
result:
wrong answer 1st words differ - expected: '237', found: '228'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%