how read() ?(悬关)
查看原帖
how read() ?(悬关)
1108078
nothing_exe_studio楼主2024/6/26 19:40

加快读全tle 不加的话只有hack tle

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], x, l, dp[N], maxn;
int g[N], cnt;
int read() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;      
    ch = getchar();            
  }
  while (ch >= '0' && ch <= '9') { 
    x = x * 10 + (ch - '0');  
    ch = getchar(); 
  }
  return x * w;
}
int main() {
    while (cin >> x) a[++l] = x;
    for (int i = 1; i <= l; i++) {
        int k = 1;
        while (k <= cnt && g[k] >= a[i]) k++;
        if (k > cnt) g[++cnt] = a[i];
        else g[k] = a[i];
    }
    cout << cnt << endl;
    cnt = 0;
    for (int i = 1; i <= l; i++) {
        int k = 1;
        while (k <= cnt && g[k] < a[i]) k++;
        if (k > cnt) g[++cnt] = a[i];
        else g[k] = a[i];
    }
    cout << cnt;
}
2024/6/26 19:40
加载中...