1 条题解
-
1廖明杰 (liaomingjie) LV 7 @ 2022-8-25 12:03:18
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int inf = 2e9; struct node { int v, p; } s[maxn]; bool cmp(node x, node y) { if (x.v == y.v) return x.p < y.p; return x.v < y.v; } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &s[i].v); s[i].p = i; } sort(s + 1, s + n + 1, cmp); int ans = 1; int f = 1,noww=inf; for (int i = 1; i <= n; ) { int j = i; while (s[j + 1].v == s[j].v && j < n) j++; if (f == 1) { if(s[j].p<noww) noww=s[i].p; else { f=0; noww=s[j].p; } //if (j == n) ans++; } else{ if(s[i].p>noww) noww=s[j].p; else{ f=1; ans++; noww=s[i].p; } } i = j+1; } printf("%d\n", ans); return 0; }
- 1
信息
- ID
- 45
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 1
- 标签
- 递交数
- 56
- 已通过
- 50
- 上传者