Temporarily, Codeforces is operating in a limited mode due to technical reasons (historical data is unavailable). This will be fixed in the next few hours. ×

AmirHoseinEsmailie's blog

By AmirHoseinEsmailie, history, 3 hours ago, In English

LIS is about subsequences, not subarrays.

If you want to solve the problem using subarrays, you can refer to this link: https://codeforces.me/problemset/problem/702/A

The LIS algorithm does not work for finding the longest increasing subarray.

The provided code implements the LIS algorithm.

This problem (https://codeforces.me/problemset/problem/264/B) is a good example of the LIS problem.


#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; #define rep(i, start, end) for (int i = start; i < end; i++) #define all(x) x.begin(), x.end() //------------------------------vector----------------------------------- template <typename T> inline void INTPUT_V(vector<T> &v) { rep(i, 0, v.size()) cin >> v[i]; } // -------------------------------------------------------------------------- #define MOD 1000000007 //#include "MyDebuger.cpp" void solve() { int n; cin >> n; vi numbers(n, 0); INTPUT_V(numbers); vector<int> dp(n, 0); rep(i, 0, n) { rep(j, 0, i) { if (numbers[j] < numbers[i] && dp[i] < dp[j] + 1) { dp[i] = dp[j] + 1; } } } //debug(dp); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); // cout.tie(0); int t = 1; // cin >> t; rep(i, 0, t) { solve(); } return 0; }
»
2 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Your code is $$$O(n^2)$$$ but LIS can be done in $$$O(n\log{n})$$$ as shown here