QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#879036 | #2570. Maximal Subsequence | ningago | ML | 0ms | 0kb | C++14 | 3.9kb | 2025-02-01 20:03:42 | 2025-02-01 20:03:48 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <cctype>
#include <set>
namespace uvu
{
#define LOCAL ____________DONT_DEFINE_ME____________
#define ll long long
#define inf 0x3f3f3f3f
// #define int long long
// #define inf 0x3f3f3f3f3f3f3f3fll
#define infll 0x3f3f3f3f3f3f3f3fll
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
char _ST_;
const int BUFSIZE = (1 << 20);
char ibuf[BUFSIZE], *iS = ibuf, *iT = ibuf;
char obuf[BUFSIZE], *oS = obuf, *oT = obuf + BUFSIZE;
char getc()
{
#ifdef LOCAL
return getchar();
#else
if(iS == iT) iT = (iS = ibuf) + fread(ibuf, 1, BUFSIZE, stdin);
return iS == iT ? EOF : *iS++;
#endif
#define getchar ERR
}
void Flush() { fwrite(obuf, 1, oS - obuf, stdout); oS = obuf; }
struct Flusher { ~Flusher(){ Flush(); } }iamflusher;
void putc(char c)
{
#ifdef LOCAL
putchar(c);
#else
*oS++ = c;
if(oS == oT) Flush();
#endif
#define putchar ERR
}
template <typename T = int> T read()
{
T x = 0, f = 1; char c = getc();
for(; !isdigit(c); c = getc()) if(c == '-') f = -1;
for(; isdigit(c); c = getc()) x = (x << 3) + (x << 1) + (c ^ 48);
return x * f;
}
template <typename T> void print(T x, char c)
{
static int sta[BUFSIZE], top;
top = 0;
if(x < 0) putc('-'), x = -x;
if(!x) sta[top = 1] = 0;
for(; x; x /= 10) sta[++top] = x % 10;
for(; top; ) putc(sta[top--] ^ 48);
if(c) putc(c);
}
int readstr(char *s, int base)
{
int idx = base - 1; char c = getc();
for(; !(isdigit(c) || isalpha(c) || c == '#' || c == '.'); c = getc());
for(; isdigit(c) || isalpha(c) || c == '#' || c == '.' ; c = getc()) s[++idx] = c;
return idx - base + 1;
}
void printf(const char *s) { for(; *s; s++) putc(*s); }
template <typename T, typename ... Args>
void printf(const char *s, T x, Args ... rest)
{
for(; *s; s++)
{
if(*s != '%') { putc(*s); continue; }
s++; if(*s == 'd') print(x, 0);
else if(*s == 'c') putc(x);
printf(s + 1, rest ...);
return;
}
}
template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
#define mod 998244353
// #define mod 1000000007
int sm(int x) { return x >= mod ? x - mod : x; }
void plus_(int &x, int y) { x = sm(x + y); }
void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b) { int res = 1; for(; b; b >>= 1, mul_(a, a)) if(b & 1) mul_(res, a); return res; }
#define N 500010
struct Lish
{
int sta[N], top;
void ins(int x) { sta[++top] = x; }
void build() { std::sort(sta + 1, sta + 1 + top); top = std::unique(sta + 1, sta + 1 + top) - sta - 1; }
int lower(int x) { return std::lower_bound(sta + 1, sta + 1 + top, x) - sta; }
}X;
int a[N], n, tr[N], dp[N], ans, lim;
void ins(int x, int z) { for(; x <= n; x += x & (-x)) ckmax(tr[x], z); }
int query(int x) { int res = 0; for(; x; x -= x & (-x)) ckmax(res, tr[x]); return res; }
std::queue <int> dq[N];
void calc(int x, int las)
{
if(x > lim) { ans--; return; }
while(!dq[x].empty() && dq[x].front() <= las) dq[x].pop();
if(dq[x].empty() || a[las] >= a[dq[x].front()]) return;
las = dq[x].front(); dq[x].pop(); calc(x + 1, las);
}
void solve()
{
// memset(h, idx = -1, sizeof(h));
ans = n = read(); for(int i = 1; i <= n; i++) X.ins(a[i] = read());
X.build(); for(int i = 1; i <= n; i++) dq[dp[i] = query((a[i] = X.lower(a[i])) - 1) + 1].push(i), ins(a[i], dp[i]), ckmax(lim, dp[i]);
while(!dq[1].empty()) calc(2, dq[1].front()), dq[1].pop();
print(ans, '\n');
}
void init()
{
}
char _ED_;
void mian()
{
debug("%.3f MB\n", abs(&_ST_ - &_ED_) / 1024.0 / 1024);
init();
for(int T = 1; T; solve(), T--);
}
#ifdef int
#undef int
#endif
}
int main()
{
uvu::mian(); return 0;
}
详细
Test #1:
score: 0
Memory Limit Exceeded
input:
3 2 1 3
output:
2