Language: C

#pragma GCC optimize("Ofast")
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

int Max(int a, int b) {return a > b ? a : b;}

#define maxn 200005

struct T {
	char mon;
	int val, mx, fst;
	int fix;
	T *lson, *rson;
} t[maxn];

int tot;

T *new_node(int v) {
	T *x = &t[++ tot];
	x->mon = 1;
	x->val = v; x->mx = v; x->fst = v;
	x->fix = rand();
	x->lson = x->rson = 0;
	return x;
}

void pushup0(T *x) {
	x->fst = x->lson ? x->lson->fst : x->val;
	char mo = 1;
	x->mx = x->val;
	if (x->lson) {
		x->mx = Max(x->mx, x->lson->mx);
		mo &= x->lson->mon && x->lson->mx < x->val;
	}
	if (x->rson) {
		x->mx = Max(x->mx, x->rson->mx);
		mo &= x->rson->mon && x->val < x->rson->fst;
	}
	x->mon = mo;
}

void pushup1(T *x) {
	x->mon = 1;
	x->fst = x->lson ? x->lson->fst : x->val;
	x->mx = x->rson ? x->rson->mx : x->val;
}

T *merge0(T *a, T *b) {
	if (!a || !b) return a ? a : b;
	if (a->fix < b->fix) {
		a->rson = merge0(a->rson, b);
		pushup0(a);
		return a;
	} else {
		b->lson = merge0(a, b->lson);
		pushup0(b);
		return b;
	}
}

T *merge1(T *a, T *b) {
	if (!a || !b) return a ? a : b;
	if (a->fix < b->fix) {
		a->rson = merge1(a->rson, b);
		pushup1(a);
		return a;
	} else {
		b->lson = merge1(a, b->lson);
		pushup1(b);
		return b;
	}
}

int split(T *x, int v, T *&a, T *&b) {
	if (!x) {a = b = 0; return v;}
	if (x->mx < v) {a = x; b = 0; return v;}
	if (x->mon) {
		if (x->fst > v) {a = 0; b = x; return b->mx;}
		if (x->val < v) {
			a = x; split(x->rson, v, a->rson, b);
			pushup1(a); return b->mx;
		} else {
			b = x; split(x->lson, v, a, b->lson);
			pushup1(b); return b->mx;
		}
	} else {
		T *ls = x->lson, *rs = x->rson;
		x->lson = x->rson = 0;
		pushup1(x);
		v = split(ls, v, a, b);
		if (x->val > v) b = merge1(b, x), v = x->val;
		else a = merge0(a, x);
		T *c, *d;
		v = split(rs, v, c, d);
		a = merge0(a, c); b = merge1(b, d);
		return v;
	}
}

T *rt;

int main() {
//	freopen("in", "r", stdin);
	srand(200);
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; ++ i) {
		int p; scanf("%d", &p);
		rt = merge0(rt, new_node(p));
	}
	int ans = 0;
	while (!rt->mon) {
		++ ans;
		T *a, *b;
		split(rt, 0, a, b);
		rt = merge0(a, b);
//		printf("%d\n", ans);
	}
	printf("%d\n", ans);
//	eprintf("time used: %.3f\n", clock() * 1.0 / CLOCKS_PER_SEC);
	return 0;
}


Compiler output:
main.c:16:9: error: unknown type name 'T'
   16 |         T *lson, *rson;
      |         ^
main.c:21:1: error: unknown type name 'T'; use 'struct' keyword to refer to the type
   21 | T *new_node(int v) {
      | ^
      | struct 
main.c: In function 'new_node':
main.c:22:9: error: unknown type name 'T'; use 'struct' keyword to refer to the type
   22 |         T *x = &t[++ tot];
      |         ^
      |         struct 
main.c:22:16: error: initialization of 'int *' from incompatible pointer type 'struct T *' [-Wincompatible-pointer-types]
   22 |         T *x = &t[++ tot];
      |                ^
main.c:23:10: error: request for member 'mon' in something not a structure or union
   23 |         x->mon = 1;
      |          ^~
main.c:24:10: error: request for member 'val' in something not a structure or union
   24 |         x->val = v; x->mx = v; x->fst = v;
      |          ^~
main.c:24:22: error: request for member 'mx' in something not a structure or union
   24 |         x->val = v; x->mx = v; x->fst = v;
      |                      ^~
main.c:24:33: error: request for member 'fst' in something not a structure or union
   24 |         x->val = v; x->mx = v; x->fst = v;
      |                                 ^~
main.c:25:10: error: request for member 'fix' in something not a structure or union
   25 |         x->fix = rand();
      |          ^~
main.c:26:10: error: request for member 'lson' in something not a structure or union
   26 |         x->lson = x->rson = 0;
      |          ^~
main.c:26:20: error: request for member 'rson' in something not a structure or union
   26 |         x->lson = x->rson = 0;
      |                    ^~
main.c: At top level:
main.c:30:14: error: unknown type name 'T'
   30 | void pushup0(T *x) {
      |              ^
main.c:45:14: error: unknown type name 'T'
   45 | void pushup1(T *x) {
      |              ^
main.c:51:1: error: unknown type name 'T'; use 'struct' keyword to refer to the type
   51 | T *merge0(T *a, T *b) {
      | ^
      | struct 
main.c:51:11: error: unknown type name 'T'
   51 | T *merge0(T *a, T *b) {
      |           ^
main.c:51:17: error: unknown type name 'T'
   51 | T *merge0(T *a, T *b) {
      |                 ^
main.c:64:1: error: unknown type name 'T'; use 'struct' keyword to refer to the type
   64 | T *merge1(T *a, T *b) {
      | ^
      | struct 
main.c:64:11: error: unknown type name 'T'
   64 | T *merge1(T *a, T *b) {
      |           ^
main.c:64:17: error: unknown type name 'T'
   64 | T *merge1(T *a, T *b) {
      |                 ^
main.c:77:11: error: unknown type name 'T'
   77 | int split(T *x, int v, T *&a, T *&b) {
      |           ^
main.c:77:24: error: unknown type name 'T'
   77 | int split(T *x, int v, T *&a, T *&b) {
      |                        ^
main.c:77:31: error: unknown type name 'T'
   77 | int split(T *x, int v, T *&a, T *&b) {
      |                               ^
main.c:103:1: error: unknown type name 'T'; use 'struct' keyword to refer to the type
  103 | T *rt;
      | ^
      | struct 
main.c: In function 'main':
main.c:111:22: error: implicit declaration of function 'merge0' [-Wimplicit-function-declaration]
  111 |                 rt = merge0(rt, new_node(p));
      |                      ^~~~~~
main.c:111:20: error: assignment to 'int *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
  111 |                 rt = merge0(rt, new_node(p));
      |                    ^
main.c:114:19: error: request for member 'mon' in something not a structure or union
  114 |         while (!rt->mon) {
      |                   ^~
main.c:116:17: error: unknown type name 'T'; use 'struct' keyword to refer to the type
  116 |                 T *a, *b;
      |                 ^
      |                 struct 
main.c:117:17: error: implicit declaration of function 'split' [-Wimplicit-function-declaration]
  117 |                 split(rt, 0, a, b);
      |                 ^~~~~
main.c:118:20: error: assignment to 'int *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
  118 |                 rt = merge0(a, b);
      |                    ^