提交时间:2024-03-30 15:05:37

运行 ID: 140404

#include<iostream> using namespace std; const int N = 1e5 + 10; int n = 0, a[N], f[N], f2[N], idx = 0, idx2 = 0; int g(int x){ int l = 1, r = idx, ret = 0; while(l <= r){ int mid = (l + r) / 2; if(x < f[mid]){ r = mid - 1; ret = mid; } else{ l = mid + 1; } } return ret; } int g2(int x){ int l = 1, r = idx2, ret = 0; while(l <= r){ int mid = (l + r) / 2; if(x >= f2[mid]){ r = mid - 1; ret = mid; } else{ l = mid + 1; } } return ret; } int main(){ while(cin >> a[n]) n++; f[0] = -1e9; f2[0] = 1e9; for(int i = 0; i < n; i++){ if(a[i] >= f[idx]) f[idx+1] = a[i], idx++; else f[g(a[i])] = a[i]; } for(int i = 0; i < n; i++){ if(a[i] < f2[idx2]) f2[idx2+1] = a[i], idx2++; else f2[g2(a[i])] = a[i]; } cout << idx2 << ' ' << idx; return 0; }