Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
140404 李树强 导弹拦截 C++ 通过 100 1 MS 288 KB 857 2024-03-30 15:05:37

Tests(10/10):


#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; }


测评信息: