UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214939#3856. 排序Anthonyyan10107ms5440kbC++1.8kb2024-11-24 11:05:092024-11-24 13:15:34

answer

#include <bits/stdc++.h>

#define int long long
#define pll pair<int, int>
#define rep(i, s, e, st) for (int i = s, __##i = e; i <= __##i; i += st)
#define per(i, s, e, st) for (int i = s, __##i = e; i <= __##i; i -= st)
#define lowbit(x) ((x) & (-(x)))
#define lc(x) ((x) << 1)
#define rc(x) (((x) << 1) | 1)
#define clr(dst, size) memset(dst, 0, (sizeof(int)) * size)
#define initval(dst, val, size) memset(dst, val, (sizeof(int)) * size)
#define cpy(from, to, size) memcpy(from, to, (sizeof(int)) * size)
#define mid(l, r) (((l) + (r)) >> 1)
#define min Min
#define max Max
#define abs Abs
#define gc getchar()

inline int read()
{
  int x = 0, f = 1;
  char ch = gc;
  while (!isdigit(ch))
  {
    if (ch == '-')
      f = -f;
    ch = gc;
  }
  while (isdigit(ch))
  {
    x = (x << 1) + (x << 3) + (ch - '0');
    ch = gc;
  }
  return x * f;
}
inline void write(int x)
{
  if (x < 0)
    putchar('-'), x = -x;
  if (x / 10)
    write(x / 10);
  putchar('0' + x % 10);
}
template <typename T>
T Abs(T x) { return x < 0 ? -x : x; }
template <typename T, typename TT>
T Min(T x, TT y) { return x < y ? x : y; }
template <typename T, typename TT>
T Max(T x, TT y) { return x > y ? x : y; }

using namespace std;

const int MAXN = 5e5 + 10;

int n;
int a[MAXN];
int max_size;
stack<int> s;

signed main()
{
#ifndef ONLINE_JUDGE
  freopen("sort.in", "r", stdin);
  freopen("sort.out", "w", stdout);
#endif
  n = read();
  rep(i, 1, n, 1) a[i] = read();
  rep(i, 1, n, 1)
  {
    int num = a[i];
    if (s.empty() || num > s.top())
      s.push(num);
    else
    {
      int pre = s.top();
      s.pop();
      if (s.empty() || s.top() < num)
        s.push(num);
      else
        s.push(pre);
    }
    max_size = max(max_size, (int)s.size());
  }
  write(max_size);
  return 0;
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1176kb

input:

475
319 474 473 472 471 183 108 346 43 466 465 464 168 462 461 309 459 458 457 456 455 38 372 312 94...

output:

9

result:

wrong answer 1st numbers differ - expected: '11', found: '9'

Subtask #2:

score: 0
Skipped

Subtask #3:

score: 10
Accepted

Test #9:

score: 10
Accepted
time: 39ms
memory: 5440kb

input:

499758
77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 ...

output:

55744

result:

ok 1 number(s): "55744"

Test #10:

score: 0
Accepted
time: 33ms
memory: 5436kb

input:

498773
255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 2...

output:

55362

result:

ok 1 number(s): "55362"

Subtask #4:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 35ms
memory: 4816kb

input:

466818
447360 121353 327541 289718 71942 242279 307652 438765 78054 253024 190170 21720 292462 72832...

output:

23

result:

wrong answer 1st numbers differ - expected: '32', found: '23'

Subtask #5:

score: 0
Skipped