alexjercan/bugnet huggingface dataset:
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int n;
  scanf("%d", &n);

  int A[n];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
  }

  int L[n];
  L[0] = A[0];
  int length = 1;
  for (int i = 1; i < n; ++i) {
    if (A[i] > L[length - 1]) {
      L[length++] = A[i];
    } else {
      int left = 0;
      int right = length;
      while (left < right) {
        int mid = (left + right) / 2;
        if (L[mid] >= A[i]) {
          right = mid;
        } else {
          left = mid + 1;
        }
      }
      L[right] = A[i];
    }
  }
  cout << length << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int n;
  scanf("%d", &n);

  int A[n + 1];
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &A[i]);
  }

  //	5
  //	1
  //	3
  //	2
  //	4
  int L[n + 1];
  L[0] = 0;
  for (int i = 1; i <= n; ++i) {
    int k = 0;
    for (int j = 0; j < i; ++j) {
      if (A[i] > A[j] && L[j] > L[k]) {
        k = j;
      }
    }
    L[i] = L[k] + 1;
  }

  int maxv = 0;
  for (int i = 1; i <= n; ++i) {
    maxv = max(maxv, L[i]);
  }
  cout << maxv << endl;

  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int n;
  scanf("%d", &n);

  int A[n];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
  }
  int L[n];
  L[0] = A[0];
  int length = 1;
  for (int i = 1; i < n; ++i) {
    if (A[i] > L[length - 1]) {
      L[length++] = A[i];
    } else {
      int left = 0;
      int right = length;
      while (left < right) {
        int mid = (left + right) / 2;
        if (L[mid] >= A[i]) {
          right = mid;
        } else {
          left = mid + 1;
        }
      }
      L[right] = A[i];
    }
  }
  cout << length << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int n;
  scanf("%d", &n);

  int A[n];
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
  }
  int L[n];
  L[0] = A[0];
  int length = 1;
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      if (A[i] > L[length - 1]) {
        L[length++] = A[i];
      } else {
        int left = 0;
        int right = length;
        while (left < right) {
          int mid = (left + right) / 2;
          if (L[mid] >= A[i]) {
            right = mid;
          } else {
            left = mid + 1;
          }
        }
        L[right] = A[i];
      }
    }
  }
  cout << length << endl;

  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
 * Contents   : AOJ DPL 1 D
 * Author     : KitauraHiromi
 * LastUpdate : 20180613
 * Since      : 20180613
 */
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
int N;
int INF = 1e9 + 1;
int dp[100001]; // dp[i]: i番目までの文字を見たときのLIS
int a[100001];
int main(void) {
  cin >> N;
  for (int i = 0; i < N; ++i)
    cin >> a[i];
  fill(dp, dp + N, INF);
  for (int i = 0; i < N; ++i) {
    *lower_bound(dp, dp + N, a[i]) = a[i];
  }
  cout << lower_bound(dp, dp + N, INF) - dp << endl;
  return 0;
}


Error: TLE

Fixed submission:

/*
 * Contents   : AOJ DPL 1 D
 * Author     : KitauraHiromi
 * LastUpdate : 20180613
 * Since      : 20180613
 */
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
int N;
int dp[100001]; // dp[i]: i番目までの文字を見たときのLIS
long long a[100001];
int main(void) {
  cin >> N;
  int res = 0;
  for (int i = 0; i < N; ++i)
    dp[i] = 1;
  for (int i = 0; i < N; ++i)
    cin >> a[i];
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < i; ++j) {
      if (a[j] < a[i])
        dp[i] = max(dp[j] + 1, dp[i]);
    }
    res = max(res, dp[i]);
  }
  cout << res << endl;
  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<ll> seq(n);
  for (int i = 0; i < n; ++i) {
    cin >> seq[i];
  }

  vector<ll> lis(n, INT_MAX);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    vector<ll>::iterator pos = lower_bound(lis.begin(), lis.end(), seq[i]);
    *pos = seq[i];
    ans = max(ans, (int)(pos - lis.begin()) + 1);
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <climits>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int n;
  cin >> n;
  vector<ll> seq(n);
  for (int i = 0; i < n; ++i) {
    cin >> seq[i];
  }

  vector<ll> lis(n, INT_MAX);
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int len = lis.size();
    for (int j = 0; j < len; ++j) {
      if (lis[j] >= seq[i]) {
        lis[j] = seq[i];
        ans = max(ans, j + 1);
        break;
      }
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int N;
  cin >> N;
  vector<long long int> dp(N + 1, LLONG_MAX / 6);
  dp[0] = LLONG_MIN;
  for (size_t i = 0; i < N; i++) {
    long long int a;
    cin >> a;
    for (size_t j = lower_bound(dp.begin(), dp.end(), a) - dp.begin() - 1;
         j < N; j++) {
      if (dp[j] < a) {
        dp[j + 1] = min(dp[j + 1], a);
      } else {
        break;
      }
    }
  }
  long long int ans = 0;
  for (size_t i = 0; i < N + 1; i++) {
    if (dp[i] != LLONG_MAX / 6) {
      ans = i;
    } else {
      break;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long int N;
  cin >> N;
  vector<long long int> dp(N + 1, LLONG_MAX / 6);
  dp[0] = LLONG_MIN;
  for (size_t i = 0; i < N; i++) {
    long long int a;
    cin >> a;
    for (size_t j = 0; j < N; j++) {
      if (dp[j] < a) {
        dp[j + 1] = min(dp[j + 1], a);
      } else {
        break;
      }
    }
  }
  long long int ans = 0;
  for (size_t i = 0; i < N + 1; i++) {
    if (dp[i] != LLONG_MAX / 6) {
      ans = i;
    } else {
      break;
    }
  }
  cout << ans << endl;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll INF = 1e10;

// Longest Increasing Subsequence at A=a_1...a_n
// O(nlogn)
// DPL_1_D: verified
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  vector<ll> dp(n + 1); // the last(maximum) value of LIS length i+1
  // (if not exist then INF)
  fill(dp.begin(), dp.end(), INF);
  for (ll i = 0; i < n; i++) {
    // lower_bound(k) returns min pointer a_i >= k
    *lower_bound(dp.begin(), dp.end(), a[i]) = a[i];
  }
  cout << ll(lower_bound(dp.begin(), dp.end(), INF) - dp.begin()) << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int dp[n];
  dp[0] = 1;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    int maxv = 1;
    for (int j = 0; j < i; j++) {
      if (a[j] < a[i])
        maxv = max(maxv, dp[j] + 1);
    }
    dp[i] = maxv;
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int lis(vector<int> a) {
  int n = a.size();
  int dp[n];
  fill(dp, dp + n, INT_MAX);
  rep(i, n) * lower_bound(dp, dp + n, a[i]) = a[i];
  return lower_bound(dp, dp + n, INT_MAX) - dp;
}
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  cout << lis(a) << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX_P 100000
int a[MAX_P];
int P;
int getLIS() {
  int dp[MAX_P];
  fill(dp, dp + P, INT_MAX);
  int res = 1;
  for (int j = 0; j < P; ++j) {
    for (int i = 0; i <= j; ++i) {
      if (i == 0 || dp[i - 1] < a[j]) {
        dp[i] = min(dp[i], a[j]);
        res = max(res, i + 1);
        if (dp[i] == a[j])
          break;
      }
    }
  }
  return res;
}
int main(void) {
  cin >> P;
  rep(i, P) cin >> a[i];
  cout << getLIS() << endl;
}
Problem p02317 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#define INF 1000000009
using namespace std;
int main() {
  int dp[100000];
  int n;
  int a[100000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  fill(dp, dp + n, INF);
  for (int i = 0; i < n; i++) {
    *lower_bound(dp, dp + n, a[i]) = a[i];
  }
  cout << lower_bound(dp, dp + n, INF) - dp << endl;
  return 0;
}


Error: 0
5
100000009
100000009
100000009
100000009


Fixed submission:

#include <algorithm>
#include <iostream>
#define INF 100000009
using namespace std;
int main() {
  int dp[100000];
  int n;
  int a[100000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  fill(dp, dp + n, INF);
  for (int i = 0; i < n; i++) {
    *lower_bound(dp, dp + n, a[i]) = a[i];
    cerr << dp[i] << endl;
  }
  cout << lower_bound(dp, dp + n, INF) - dp << endl;
  cin >> n;
  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int a[100000];
int main() {
  int n;
  scanf("%d", &n);
  memset(a, 0x3f, sizeof(a));
  for (int i = 0, x; i < n; i++) {
    scanf("%d", &x);
    *lower_bound(a, a + n, x) = x;
  }
  printf("%d\\n", lower_bound(a, a + n, 0x3f3f3f3f) - a);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int dp[100000], a[100000];
signed main(void) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i);
  for (int i = 1; i <= n; i++) {
    dp[i] = 1;
    for (int j = 1; j < i; j++)
      if (a[j] < a[i])
        dp[i] = max(dp[i], dp[j] + 1);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans = max(ans, dp[i]);
  printf("%d\\n", ans);
  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int rec[100001];
int len[100001];

int main() {

  int con, ptr = 0, sum = 0;
  scanf("%d", &con);
  while (con--) {
    scanf("%d", &rec[ptr]);
    // len[ptr] = 1;
    ptr++;
  }

  vector<int> v;
  v.push_back(rec[0]);

  for (int i = 1; i < ptr; ++i) {
    int n = rec[i];

    if (n > v.back())
      v.push_back(n);
    else {
      // printf("      %d\\n", *lower_bound(v.begin(), v.end(), n));
      *lower_bound(v.begin(), v.end(), n) = n;
    }
    // for(int g = 0; g < v.size(); ++g)printf("%d ", v[g]);
    // printf("\\n");
  }

  printf("%d\\n", v.size());

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int rec[100000];
int len[100000];

int main() {

  int con, ptr = 0, sum = 0;
  scanf("%d", &con);
  while (con--) {
    scanf("%d", &rec[ptr]);
    len[ptr] = 1;
    ptr++;
  }
  for (int i = 0; i < ptr; ++i) {
    for (int j = i + 1; j < ptr; ++j) {
      if (rec[i] < rec[j])
        len[j] = max(len[j], len[i] + 1);
    }
  }
  for (int g = 0; g < ptr; ++g) {
    sum = max(len[g], sum);
    // printf("%d %d\\n", len[g], rec[g]);
  }
  printf("%d\\n", sum);

  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int *)a, (int *)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define MAX_N 100000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int dp[MAX_N + 1];
int n, a[MAX_N];

int main() {
  scanf("%d", &n);
  rep(i, n) scanf("%d", a + i);

  fill(dp, dp + n, INF);
  rep(i, n) { *lower_bound(dp, dp + n, a[i]) = a[i]; }
  printf("%d\\n", lower_bound(dp, dp + n, INF) - dp);

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (int i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int *)a, (int *)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define MAX_N 100000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int dp[MAX_N + 1];
int n, a[MAX_N];

int main() {
  scanf("%d", &n);
  rep(i, n) scanf("%d", a + i);
  int res = 0;
  rep(i, n) {
    dp[i] = 1;
    rep(j, i) {
      if (a[i] > a[j])
        dp[i] = max(dp[j] + 1, dp[i]);
    }
    res = max(res, dp[i]);
  }

  printf("%d\\n", res);

  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 100010;
ll a[MAX_N] = {0};
ll dp[MAX_N];
int main() {
  int n;
  cin >> n;
  fill(dp, dp + n, 10e8);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    int pos = lower_bound(dp, dp + n, a[i]) - dp;
    dp[pos] = a[i];
  }
  cout << lower_bound(dp, dp + n, 10e8) - dp << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

int dp[100010] = {0};
int main() {
  int n;
  cin >> n;
  int a[100010] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) { // 一番右
    dp[i] = 1;
    for (int j = 0; j < i; j++) {
      if (a[i] > a[j] && dp[i] < dp[j] + 1) {
        dp[i] = dp[j] + 1;
      }
      if (ans < dp[i]) {
        ans = dp[i];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>

using namespace std;

int b[100001];

int main() {

  int n, temp;
  vector<int> a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    a.push_back(temp);
  }
  fill(b, b + n, 1 << 30);
  for (int i = 0; i < n; i++) {
    *lower_bound(b, b + n, a[i]) = a[i];
  }
  int res = 0;
  res = lower_bound(b, b + n, 1 << 30) - b;

  cout << res << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <vector>

using namespace std;

int b[10001];

int main() {

  int n, temp;
  vector<int> a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    a.push_back(temp);
  }
  fill(b, b + n, 1 << 30);
  for (int i = 0; i < n; i++) {
    *lower_bound(b, b + n, a[i]) = a[i];
  }
  int res = 0;
  res = lower_bound(b, b + n, 1 << 30) - b;

  cout << res << endl;

  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

const double pi = 4 * atan(1.0);

int mod = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int> arr(N);
  for (auto &val : arr)
    cin >> val;

  vector<int> dp(N);

  int ans = 0;
  dp[0] = arr[0];
  for (int i = 1; i < N; ++i) {
    if (arr[i] > dp[ans]) {
      dp[++ans] = arr[i];
    } else {

      int min = 0, max = ans;
      int mid;
      while (1) {
        mid = (max - min) / 2 + min;

        if (dp[mid] > arr[i]) {
          if (min == mid)
            break;
          max = mid;
        } else if (dp[mid] < arr[i]) {
          if (min == mid) {
            ++mid;
            break;
          }
          min = mid;
        } else {
          break;
        }
      }

      dp[mid] = arr[i];
    }
  }

  cout << ans + 1 << endl;

  // system("pause");
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <array>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

const double pi = 4 * atan(1.0);

int mod = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int> arr(N);
  for (auto &val : arr)
    cin >> val;

  vector<int> dp(N);
  dp[0] = 1;

  for (int i = 1; i < N; ++i) {
    int MAX = 0;
    for (int j = 0; j < i; ++j) {
      if (arr[i] > arr[j]) {
        MAX = max(MAX, dp[j]);
      }
      dp[i] = MAX + 1;
    }
  }

  int ans = 0;
  for (const auto &val : dp) {
    ans = max(ans, val);
  }

  cout << ans << endl;

  // system("pause");
  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <set>
using namespace std;
#define MAX_N (100010)
int L[MAX_N];
int main() {
  int n;
  int length = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int d;
    scanf("%d", &d);

    int *pos = lower_bound(L, L + length, d);

    if (pos == L + length) {
      L[length] = d;
      length++;
    } else {
      *pos = d;
    }
  }

  printf("%d\\n", length);

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <set>
using namespace std;
#define MAX_N (100010)
// int a[MAX_N];

int main() {
  int n;
  set<int> LIS;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int d;
    scanf("%d", &d);
    set<int>::iterator it = lower_bound(LIS.begin(), LIS.end(), d);
    if (it != LIS.end()) {
      LIS.erase(*it);
    }

    LIS.insert(d);
  }

  printf("%d\\n", (int)LIS.size());

  return 0;
}
Problem p02317 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <set>
#include <tuple>
using namespace std;

typedef tuple<int, int> seq; // tail, length
const int infty = 1e9 + 10;

int main() {
  int n;
  cin >> n;
  int a[100010];
  for (auto i = 0; i < n; i++) {
    cin >> a[i];
  }
  set<seq> S;
  S.insert(make_tuple(infty, 100010));
  S.insert(make_tuple(-1, 0));
  for (auto i = 0; i < n; i++) {
    auto it = S.lower_bound(make_tuple(a[i], -1));
    it--;
    seq temp = *it;
    get<0>(temp) = a[i];
    int tl = ++get<1>(temp);
    S.insert(temp);
    // cerr << "insert: " << get<0>(temp) << " " << get<1>(temp) << endl;
    it++;
    it++;
    while (it != S.end() && get<1>(*it) <= tl) {
      // cerr << "erase: " << get<0>(*it) << " " << get<1>(*it) << endl;
      S.erase(it++);
    }
  }
  auto it = S.end();
  it--;
  it--;
  cout << get<1>(*it) << endl;
}

Error: 0
insert: 5 1
insert: 1 1
erase: 5 1
insert: 3 2
insert: 2 2
erase: 3 2
insert: 4 3


Fixed submission:

#include <iostream>
#include <set>
#include <tuple>
using namespace std;

typedef tuple<int, int> seq; // tail, length
const int infty = 1e9 + 10;

int main() {
  int n;
  cin >> n;
  int a[100010];
  for (auto i = 0; i < n; i++) {
    cin >> a[i];
  }
  set<seq> S;
  S.insert(make_tuple(infty, 100010));
  S.insert(make_tuple(-1, 0));
  for (auto i = 0; i < n; i++) {
    auto it = S.lower_bound(make_tuple(a[i], -1));
    it--;
    seq temp = *it;
    get<0>(temp) = a[i];
    int tl = ++get<1>(temp);
    S.insert(temp);
    cerr << "insert: " << get<0>(temp) << " " << get<1>(temp) << endl;
    it++;
    it++;
    while (it != S.end() && get<1>(*it) <= tl) {
      cerr << "erase: " << get<0>(*it) << " " << get<1>(*it) << endl;
      S.erase(it++);
    }
  }
  auto it = S.end();
  it--;
  it--;
  cout << get<1>(*it) << endl;
}
Problem p02317 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;

int n, a[100001];
int dp[100001];

// LIS

int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  fill(dp, dp + n, INF);
  for (int i = 0; i < n; i++) {
    *lower_bound(dp, dp + n, a[i]) = a[i];
  }
  cout << lower_bound(dp, dp + n, INF) - dp << endl;
  return 0;
}

/*
int main(void) {
        cin >> n;
        for (int i = 0; i < n; i++) {
                cin >> a[i];
        }

        int res = 0;
        for (int i = 0; i < n; i++) {
                dp[i] = 1;
                for (int j = 0; j < i; j++) {
                        if (a[j] < a[i]) {
                                dp[i] = max(dp[i], dp[j] + 1);;
                        }
                }
                res = max(res, dp[i]);
        }
        cout << res << endl;
        return 0;
}
*/


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;

int n, a[100001];
int dp[100001];

// LIS

/*
int main(void) {
        cin >> n;
        for (int i = 0; i < n; i++) {
                cin >> a[i];
        }
        fill(dp, dp + n, INF);
        for (int i = 0; i < n; i++) {
                *lower_bound(dp, dp + n, a[i]) = a[i];
        }
        cout << lower_bound(dp, dp + n, INF) - dp << endl;
        return 0;
}
*/

int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  int res = 0;
  for (int i = 0; i < n; i++) {
    dp[i] = 1;
    for (int j = 0; j < i; j++) {
      if (a[j] < a[i]) {
        dp[i] = max(dp[i], dp[j] + 1);
        ;
      }
    }
    res = max(res, dp[i]);
  }
  cout << res << endl;
  return 0;
}