text
stringlengths
49
983k
#include <bits/stdc++.h> using ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; void test_case() { int n; cin >> n; vector<int> data(n + 1); vector<bool> missing_l(n + 1), missing_r(n + 1); unordered_set<int> run_missing; vector<bool> found(n + 1); for (int i = 1; i <= n; i++) { cin >> data[i]; found[data[i]] = true; auto it = run_missing.find(data[i]); if (it != run_missing.end()) { run_missing.erase(it); } if (found[i] == false) { run_missing.insert(i); } missing_l[i] = run_missing.empty(); } run_missing.clear(); found.clear(); found.resize(n + 1, 0); for (int i = n; i > 0; i--) { found[data[i]] = true; auto it = run_missing.find(data[i]); if (it != run_missing.end()) { run_missing.erase(it); } if (found[n - i + 1] == false) { run_missing.insert(n - i + 1); } missing_r[i] = run_missing.empty(); } vector<pair<int, int>> possible; for (int i = 1; i < n; i++) { if (missing_l[i] && missing_r[i + 1]) { possible.push_back({i, n - i}); } } cout << possible.size() << '\n'; for (pair<int, int> x : possible) { cout << x.first << ' ' << x.second << '\n'; } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; for (int i = 0; i < t; i++) { test_case(); } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int tc = 1; while (t--) { int n; cin >> n; int a[n + 2], f = 0; vector<pair<int, int> > p; for (int i = 1; i <= n; i++) { cin >> a[i]; f = max(a[i], f); } if (f == n) { cout << "0" << endl; } else { int cnt = 0, s = 0, flag = 0; set<int> se; for (int i = 1; i <= f; i++) { se.insert(a[i]); if (se.size() == s || a[i] > f) { flag++; break; } s++; } if (flag == 0) { se.clear(); s = 0, flag = 0; for (int i = f + 1; i <= n; i++) { se.insert(a[i]); if (se.size() == s || a[i] > n - f) { flag++; break; } s++; } if (flag == 0) { p.push_back(make_pair(f, n - f)); cnt++; } } se.clear(); s = 0, flag = 0; for (int i = 1; i <= n - f; i++) { se.insert(a[i]); if (se.size() == s || a[i] > n - f) { flag++; break; } s++; } if (flag == 0) { se.clear(); s = 0, flag = 0; for (int i = n - f + 1; i <= n; i++) { se.insert(a[i]); if (se.size() == s || a[i] > f) { flag++; break; } s++; } if (flag == 0) { p.push_back(make_pair(n - f, f)); cnt++; } } if (n - f == f && cnt == 2) cnt--; cout << cnt << endl; for (int i = 0; i < cnt; i++) cout << p[i].first << " " << p[i].second << endl; } } }
#include <bits/stdc++.h> using namespace std; bool pa[200005], pb[200005], fa[200005], fb[200005]; int main() { int n, T, t, panduan, i, s, sum, d[200005]; scanf("%d", &T); while (T--) { panduan = 1; sum = 0; scanf("%d", &n); for (i = 1; i <= n; i++) scanf("%d", &d[i]); for (i = 1; i <= n; i++) { pa[i] = 0; pb[i] = 0; fa[i] = 0; fb[i] = 0; } for (i = 1, t = -1, s = 0; i <= n; i++) { t = max(t, d[i]); if (pa[d[i]] == 0) { pa[d[i]] = 1; if (d[i] <= t) s++; } else if (d[i] <= t) { panduan = 0; break; } if (s == t) fa[i] = 1; } for (i = n, t = -1, s = 0; i >= 1; i--) { t = max(t, d[i]); if (pb[d[i]] == 0) { pb[d[i]] = 1; if (d[i] <= t) s++; } else if (d[i] <= t) { panduan = 0; break; } if (s == t) fb[i] = 1; } for (i = 1; i <= n - 1; i++) if (fa[i] == 1 && fb[i + 1] == 1) sum++; printf("%d\n", sum); for (i = 1; i <= n; i++) if (fa[i] == 1 && fb[i + 1] == 1) printf("%d %d\n", i, n - i); } return 0; }
#include <bits/stdc++.h> using namespace std; long long n, a[200050]; bool ok1[200050], ok2[200050], vis1[200050], vis2[200050]; signed main() { long long t; cin >> t; while (t--) { cin >> n; for (long long i = 1; i <= n; i++) cin >> a[i]; for (long long i = 1, mx = 0, cnt = 0; i <= n; i++) { if (!vis1[a[i]]) { vis1[a[i]] = 1; if (mx < a[i]) cnt += a[i] - mx, mx = a[i]; cnt--; if (!cnt) ok1[i] = 1; } else break; } for (long long i = n, mx = 0, cnt = 0; i; i--) { if (!vis2[a[i]]) { vis2[a[i]] = 1; if (mx < a[i]) cnt += a[i] - mx, mx = a[i]; cnt--; if (!cnt) ok2[i] = 1; } else break; } vector<long long> res; for (long long i = 1; i < n; i++) if (ok1[i] and ok2[i + 1]) res.push_back(i); for (long long i = 1; i <= n; i++) ok1[i] = ok2[i] = vis1[a[i]] = vis2[a[i]] = 0; cout << res.size() << '\n'; for (auto x : res) cout << x << ' ' << n - x << '\n'; } }
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n, i, j; cin >> n; long long int a[n + 1]; for (i = 0; i < n; i++) cin >> a[i]; map<long long int, long long int> m1, m2; vector<long long int> l1; vector<long long int> l2; long long int m = -1; for (i = 0; i < n; i++) { m1[a[i]]++; if (m1[a[i]] > 1) break; m = max(m, a[i]); if (m == i + 1) l1.push_back(i + 1); } m = -1; for (i = n - 1; i >= 0; i--) { m2[a[i]]++; if (m2[a[i]] > 1) break; m = max(m, a[i]); if (m == n - i) l2.push_back(n - i); } vector<long long int>::iterator itr; vector<long long int>::iterator itr1; long long int cnt = 0; vector<pair<long long int, long long int>> p; sort(l1.begin(), l1.end()); sort(l2.begin(), l2.end()); long long int x1 = l1.size(); long long int y1 = l2.size(); i = 0, j = y1 - 1; while (i < x1 && j >= 0) { if (l1[i] + l2[j] == n) { p.push_back(make_pair(l1[i], l2[j])); i++; j--; cnt++; } else if ((l1[i] + l2[j]) < n) i++; else j--; } cout << cnt << "\n"; for (i = 0; i < p.size(); i++) cout << p[i].first << " " << p[i].second << "\n"; } }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 1000; int n; int a[maxn]; void solve() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int pre[maxn] = {0}, Hou[maxn] = {0}, p[maxn] = {0}; int maxx = -1, minn = 1e8; for (int i = 1; i < n; i++) { p[a[i]]++; maxx = max(maxx, a[i]); minn = min(minn, a[i]); if (maxx != i || minn != 1) { pre[i] = -1; } if (p[a[i]] > 1) { for (int k = i; k < n; k++) pre[k] = -1; break; } } memset(p, 0, sizeof(p)); maxx = -1; minn = 1e8; for (int i = n; i > 1; i--) { p[a[i]]++; maxx = max(maxx, a[i]); minn = min(minn, a[i]); if (maxx != n - i + 1 || minn != 1) { Hou[i] = -1; } if (p[a[i]] > 1) { for (int k = i; k > 1; k--) Hou[k] = -1; break; } } vector<int> q; for (int i = 1; i < n; i++) { if (pre[i] == 0 && Hou[i + 1] == 0) { q.push_back(i); } } int ans = q.size(); printf("%d\n", ans); for (int i = 0; i < ans; i++) { printf("%d %d\n", q[i], n - q[i]); } return; } int main() { int t; scanf("%d", &t); while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); template <typename T> void chmin(T &x, const T &y) { if (x > y) x = y; } template <typename T> void chmax(T &x, const T &y) { if (x < y) x = y; } template <typename T> T gcd(T x, T y) { return y ? gcd(y, x % y) : x; } const int N = 2e5 + 5; int n, a[N], mx; int l[N], r[N]; set<int> s; vector<pair<int, int> > p; void solve(int times) { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; mx = 0; s.clear(); for (int i = 1; i <= n; ++i) { chmax(mx, a[i]); s.insert(a[i]); if (mx == i && s.size() == i) { l[i] = true; } else l[i] = false; } mx = 0; s.clear(); for (int i = n; i >= 1; --i) { chmax(mx, a[i]); s.insert(a[i]); if (mx == n - i + 1 && s.size() == n - i + 1) { r[i] = true; } else r[i] = false; } p.clear(); for (int i = 1; i < n; ++i) { if (l[i] && r[i + 1]) p.push_back(make_pair(i, n - i)); } cout << p.size() << endl; for (int i = 0; i < p.size(); ++i) { cout << p[i].first << ' ' << p[i].second << endl; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int times = 1; int T; cin >> T; for (; T--;) { solve(times++); } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 50; int vis[maxn], a[maxn], ok1[maxn], ok2[maxn]; vector<pair<int, int> > ans; void solve() { ans.clear(); int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), vis[i] = ok1[i] = ok2[i] = 0; int cnt = 0, mx = 0; for (int i = 1; i <= n; i++) { if (!vis[a[i]]) vis[a[i]] = 1, cnt++; mx = max(mx, a[i]); if (i == cnt && mx == cnt) ok1[i] = 1; } for (int i = 1; i <= n; i++) vis[i] = 0; cnt = 0, mx = 0; for (int i = n; i >= 1; i--) { if (!vis[a[i]]) vis[a[i]] = 1, cnt++; mx = max(mx, a[i]); if (n - i + 1 == cnt && mx == cnt) ok2[i] = 1; } for (int i = 1; i < n; i++) { if (ok1[i] && ok2[i + 1]) ans.push_back({i, n - i}); } printf("%d\n", ans.size()); for (int i = 0; i < ans.size(); i++) printf("%d %d\n", ans[i].first, ans[i].second); } int main() { int t; scanf("%d", &t); while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; void is_permu(vector<int> &v, vector<int> &ans) { int n = v.size(), j = 1; vector<int> c(n); for (int i = 0; i < n; i++) { c[v[i]]++; if (c[v[i]] == 2) break; while (c[j] == 1 && j < n) { j++; } if (i + 1 == j - 1) ans[i] = 1; } return; } void sherlock(int t) { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } vector<int> ans(n), ansr(n); is_permu(v, ans); reverse(v.begin(), v.end()); is_permu(v, ansr); vector<pair<int, int>> ansf; for (int i = 0; i < n - 1; i++) { if (ans[i] && ansr[n - i - 2]) { ansf.push_back({i + 1, n - i - 1}); } } cout << ansf.size() << endl; for (auto x : ansf) { cout << x.first << " " << x.second << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tt; cin >> tt; for (int t = 1; t <= tt; t++) sherlock(t); return 0; }
#include <bits/stdc++.h> using namespace std; long long int arr[100005], dp[100005]; int main() { int t, n, k; cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; long long int res = 0; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { dp[i] = 1; long long int ans = 1; for (int j = 1; j * j <= i; j++) { if (i % j == 0 && arr[j] < arr[i]) { ans = max(ans, dp[j] + 1); } int d = i / j; if (d != j) { if (i % d == 0 && arr[d] < arr[i]) ans = max(ans, dp[d] + 1); } } dp[i] = max(ans, dp[i]); res = max(dp[i], res); } cout << res << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int arr[n + 1]; for (long long int i = 1; i <= n; i++) cin >> arr[i]; long long int dp[n + 1]; fill(dp, dp + n + 1, 1); for (long long int i = n / 2; i >= 1; i--) { for (long long int j = i + i; j <= n; j += i) { if (arr[j] > arr[i]) { dp[i] = max(dp[i], 1 + dp[j]); } } } long long int mx = 0; for (long long int i = 1; i <= n; i++) mx = max(dp[i], mx); cout << mx << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int arr[100000], fa[100000]; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int i = 1; i <= n; i++) fa[i] = 1; int max1 = 1; for (int i = 1; i <= n; i++) { for (int j = 2 * i; j <= n; j += i) { if (arr[i] < arr[j]) fa[j] = max(fa[j], fa[i] + 1); } } for (int i = 1; i <= n; i++) { if (fa[i] > max1) max1 = fa[i]; } cout << max1 << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; long long a[200005], dp[200005]; int main() { long long n, k; long long T; cin >> T; while (T--) { scanf("%lld", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); dp[i] = 1; } for (int i = 1; i <= n; i++) { for (int j = i * 2; j <= n; j += i) { if (a[j] > a[i]) dp[j] = max(dp[j], dp[i] + 1); } } long long ans = 0; for (int i = 1; i <= n; i++) { ans = max(ans, dp[i]); } printf("%lld\n", ans); } }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int t, n, i, j, ans, a[N], dp[N]; int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); for (i = 1; i <= n; ++i) scanf("%d", a + i), dp[i] = 0; for (i = 1; i <= n; ++i) { dp[i] = max(dp[i], 1); for (j = i + i; j <= n; j += i) if (a[j] > a[i]) dp[j] = max(dp[j], dp[i] + 1); } ans = 0; for (i = 1; i <= n; ++i) ans = max(ans, dp[i]); printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> const int LIM = 1e5; using namespace std; set<int> nums; void getdiv(int x) { for (int i = 1; i * i <= x; i++) if (x % i == 0) { nums.insert(i); nums.insert(x / i); } } void solve() { int n; cin >> n; vector<int> s(n, 0); vector<int> dp(n, 0); for (int i = 0; i < n; i++) cin >> s[i]; for (int ind = 1; ind <= n; ind++) { nums.clear(); getdiv(ind); dp[ind - 1] = 1; for (int x : nums) { if (s[x - 1] < s[ind - 1]) dp[ind - 1] = max(dp[ind - 1], dp[x - 1] + 1); } } int ans = 0; for (int i = 0; i < n; i++) ans = max(ans, dp[i]); cout << ans << "\n"; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; inline void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } signed main() { fastio(); long long T; cin >> T; while (T--) { long long n; cin >> n; vector<long long> s(n); for (long long i = 0; i < n; i++) cin >> s[i]; vector<long long> m(n, 1); long long ans = 1; for (long long i = 1; i <= n; i++) { long long j = 2 * i; while (j <= n) { if (s[j - 1] > s[i - 1]) m[j - 1] = max(m[j - 1], m[i - 1] + 1); j += i; } ans = max(ans, m[i - 1]); } cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, i, j; cin >> n; int a[n + 1]; int dp[n + 1]; for (i = 1; i <= n; i++) cin >> a[i]; for (i = 1; i <= n; i++) dp[i] = 1; for (i = 1; i <= n; i++) { for (j = 2 * i; j <= n; j = j + i) { if (a[i] < a[j]) { dp[j] = max(dp[j], dp[i] + 1); } } } int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, dp[i]); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int binpow(int a, int n) { if (n == 0) return 1; if (n & 1) { return binpow(a, n - 1) * a; } int b = binpow(a, n / 2); return b * b; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n + 1), dp(n + 1, 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } dp[1] = 1; for (int i = 2; i <= n; i++) { for (int j = 1; j * j <= i; j++) { if (!(i % j)) { if (a[j] < a[i]) dp[i] = max(dp[i], dp[j] + 1); if (a[i / j] < a[i]) dp[i] = max(dp[i], dp[i / j] + 1); } } } int ans = 1; for (int i = 1; i <= n; i++) { ans = max(ans, dp[i]); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; for (long long i = 0; i < n; i++) cin >> a[i]; long long b[n + 1]; for (long long i = 0; i <= n; i++) { b[i] = 1; } for (long long i = 1; i < n; i++) { for (long long j = 1; j <= sqrt(i + 1); j++) { if ((i + 1) % j == 0) { if (a[j - 1] < a[i]) { b[i + 1] = max(b[i + 1], b[j] + 1); } long long d = (i + 1) / j; if (a[d - 1] < a[i]) { b[i + 1] = max(b[i + 1], b[d] + 1); } } } } long long maxi = 0; for (long long i = 1; i <= n; i++) { maxi = max(maxi, b[i]); } cout << maxi << "\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); long long t; cin >> t; while (t--) { long long n, s, i, j, ans = 0; cin >> n; long long a[n + 1], b[n + 1]; for (i = 1; i <= n; i++) { cin >> a[i]; b[i] = 1; } for (i = 1; i <= n; i++) { for (j = 2; j * i <= n; j++) { if (a[i * j] > a[i]) { b[i * j] = max(b[i * j], b[i] + 1); } } } for (i = 1; i <= n; i++) { if (b[i] > ans) { ans = b[i]; } } cout << ans << "\n"; } }
#include <bits/stdc++.h> using namespace std; long long fact[100005]; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; while (y > 0) { if (y & 1) res = ((res % p) * (x % p)) % p; y = y >> 1; x = ((x % p) * (x % p)) % p; } return res; } long long modInverse(long long n, long long p) { return power(n, p - 2, p); } long long nCrModFermat(long long n, long long r, long long p) { if (r == 0 || r == n) return 1; return (((fact[n] % p) * (modInverse(fact[r], p) % p)) % p * (modInverse(fact[n - r], p) % p)) % p; } void sieve(vector<bool> &isPrime) { long long n = isPrime.size(); isPrime[0] = false; isPrime[1] = false; for (long long i = 2; i * i <= n; i++) { if (isPrime[i] == true) { for (long long j = i * i; j <= n; j += i) isPrime[j] = false; } } } void addEdge(vector<long long> adj[], long long u, long long v) { adj[u].push_back(v); } void BFS(long long s, vector<long long> adj[], vector<bool> &visited) { deque<long long> q; q.push_back(s); visited[s] = true; cout << s << " "; while (!q.empty()) { long long p = q.front(); q.pop_front(); for (long long i = 0; i < adj[p].size(); i++) { if (visited[adj[p][i]] == false) { q.push_back(adj[p][i]); visited[adj[p][i]] = true; cout << adj[p][i] << " "; } } } } void DFSUtil(long long u, vector<long long> adj[], vector<bool> &visited) { visited[u] = true; cout << u << " "; for (long long i = 0; i < adj[u].size(); i++) if (visited[adj[u][i]] == false) DFSUtil(adj[u][i], adj, visited); } void DFS(vector<long long> adj[], long long V) { vector<bool> visited(V, false); for (long long u = 0; u < V; u++) if (visited[u] == false) DFSUtil(u, adj, visited); } void ChubbyCoder() { long long n; cin >> n; long long arr[n + 1]; for (long long i = 1; i < n + 1; i++) cin >> arr[i]; vector<long long> dp(n + 1, 1); for (long long i = 1; i <= n; i++) { for (long long j = 2 * i; j <= n; j += i) { if (arr[i] < arr[j]) { dp[j] = max(dp[j], dp[i] + 1); } } } cout << *max_element(dp.begin(), dp.end()) << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t; t = 1; cin >> t; while (t--) { ChubbyCoder(); } return 0; }
#include <bits/stdc++.h> using namespace std; int A[100002]; int n; void printVector(vector<int> L) { cout << "[ "; for (int x : L) { cout << x << ", "; } cout << "]\n"; } int DP(int i, vector<int> &memo) { if (i > n) { return 0; } else { if (memo[i] != -1) { return memo[i]; } vector<int> results; for (int k = 2 * i; k <= n; k += i) { if (A[k - 1] > A[i - 1]) results.push_back(DP(k, memo)); else DP(k, memo); } if (results.size() > 0) { int max_elem = *max_element(results.begin(), results.end()); memo[i] = 1 + max_elem; return 1 + max_elem; } else { memo[i] = 1; return 1; } } } int main() { ios_base::sync_with_stdio(true); cin.tie(NULL); cout.tie(NULL); int epochs; cin >> epochs; for (int i = 0; i < epochs; i++) { cin >> n; for (int j = 0; j < n; j++) { cin >> A[j]; } vector<int> memo(n + 1, -1); DP(1, memo); int max_elem = *max_element(memo.begin(), memo.end()); cout << max_elem << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); int t; cin >> t; for (int u = 0; u < t; u++) { int n; cin >> n; vector<int> s(n + 1); for (int i = 0; i < n; i++) cin >> s[i + 1]; vector<int> d(n + 1, 1); for (int i = 1; i < n + 1; i++) { for (int j = i; j < n + 1; j += i) { if (s[j] > s[i]) d[j] = max(d[j], d[i] + 1); } } int ans = 0; for (int i = 0; i < n + 1; i++) ans = max(ans, d[i]); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1], dp[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; dp[i] = 1; if (a[i] > a[1]) { dp[i] += 1; } } for (int i = 1; i <= n; i++) { for (int j = 2 * i; j <= n; j += i) { if (a[j] > a[i]) { dp[j] = max(dp[j], dp[i] + 1); } } } int mx = 1; for (int i = 1; i <= n; i++) { mx = max(mx, dp[i]); } cout << mx << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t = 1; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; ++i) { cin >> a[i]; } int dp[n + 1]; for (int i = 0; i <= n; ++i) dp[i] = 1; for (int i = 1; i <= n; ++i) { for (int j = 2 * i; j <= n; j += i) if (a[j] > a[i]) dp[j] = max(dp[j], dp[i] + 1); } cout << *max_element(dp, dp + n + 1); cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; constexpr long long INF = numeric_limits<long long>::max() / 4; constexpr long long n_max = 2e5 + 10; template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char c) { return to_string((string)&c); } string to_string(bool b) { return (b ? "true" : "false"); } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]); return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) res += ", "; first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); long long t; cin >> t; for (long long _ = 0; _ < (long long)(t); _++) { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < (long long)(n); i++) cin >> a[i]; vector<long long> dp(n + 1); for (long long i = 1; i < (long long)(n) + 1; i++) { dp[i]++; for (long long j = i * 2; j <= n; j += i) { if (a[j - 1] > a[i - 1]) chmax(dp[j], dp[i]); } } long long ans = 0; for (long long i = 0; i < (long long)(n + 1); i++) chmax(ans, dp[i]); cout << ans << "\n"; } }
#include <bits/stdc++.h> using namespace std; vector<long long>::iterator ptr; long long count = 0; long long cache[10004]; long long dp[100005] = {0}; long long v[200005] = {0}; long long a[200005] = {0}; long long b[200005] = {0}; long long pr(long long n) { if (n % 2 == 0) { return 2; } for (long long i = 3; i <= sqrt(n); i = i + 2) { if (n % i == 0) return i; } if (n > 2) return n; } long long power(long long x, unsigned long long y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return x * power(x, y / 2) * power(x, y / 2); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n, sum = 0; long long a[200005] = {0}; cin >> n; long long dp[100005] = {0}; for (long long i = 1; i <= n; ++i) { cin >> a[i]; } for (long long i = 1; i <= n; ++i) { dp[i] = 1; } for (long long i = 1; i <= n; i++) { for (long long j = 2 * i; j <= n; j += i) { if (a[i] < a[j]) dp[j] = max(dp[i] + 1, dp[j]); } } long long m = dp[1]; for (long long i = 2; i <= n; i++) { if (m < dp[i]) m = dp[i]; } cout << m << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int n; int len[1000000 + 5]; int input[1000000 + 5]; int ans; int get_len(int idx) { if (len[idx] != -1) return len[idx]; len[idx] = 1; for (int k = 2; 1LL * k * idx <= n; ++k) { int cur = get_len(k * idx) + 1; if (input[idx] >= input[k * idx]) continue; if (cur > len[idx]) len[idx] = cur; } if (len[idx] > ans) ans = len[idx]; return len[idx]; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int t; scanf("%d", &t); while (t--) { scanf("%d", &n); ans = 0; for (int i = 1; i <= n; ++i) len[i] = -1; for (int i = 1; i <= n; ++i) scanf("%d", &input[i]); get_len(1); printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; int f[n + 1], ans = INT_MIN; fill_n(f, n + 1, 1); for (int i = n; i >= 1; i--) { int maxx = 0; for (int j = 2 * i; j <= n; j += i) { if (a[j] > a[i]) { maxx = max(maxx, f[j]); } } f[i] = max(f[i], maxx + 1); ans = max(ans, f[i]); } cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; void flush() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); } int n; int a[100009]; int dp[100009]; int solve(int i) { if (2 * i > n) return 0; if (dp[i] != -1) return dp[i]; int r = 0; for (int j = 2 * i; j <= n; j += i) { if (a[j] > a[i]) r = max(r, solve(j) + 1); } return dp[i] = r; } int main() { flush(); int t; cin >> t; while (t--) { cin >> n; memset(dp, -1, sizeof(dp)); for (int i = 1; i <= n; i++) cin >> a[i]; int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, solve(i) + 1); cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; const char NL = '\n'; long long int n; vector<long long int> a, dp; long long int s(long long int i, long long int j) { if (a[i] > a[j]) return dp[j] + 1; return 1; } void solve() { for (long long int i = 2; i < n + 1; i++) { long long int m = 1; for (long long int j = 1; (j * j <= i && j <= n); j++) { if (i % j == 0) { m = max({m, s(i, j), s(i, i / j)}); } } dp[i] = m; } cout << *max_element(dp.begin(), dp.end()) << NL; return; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { cin >> n; a.assign(n + 1, 0); dp.assign(n + 1, 0); dp[1] = 1; for (long long int i = 1; i < n + 1; i++) { cin >> a[i]; } solve(); } fflush(stdin); fflush(stdout); return 0; }
#include <bits/stdc++.h> using namespace std; int n, t, ans; int num[1000005], f[1000005]; int main() { scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &num[i]); f[i] = 1; } ans = 0; for (int i = 1; i <= n; i++) { for (int j = i * 2; j <= n; j += i) { if (num[i] < num[j]) f[j] = max(f[j], f[i] + 1); } ans = max(ans, f[i]); } printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int dp[100004]; int n; int a[100004]; int func(int ind) { if (ind > n) return 0; if (dp[ind] != -1) return dp[ind]; int count = 0; for (int i = 2 * ind; i <= n; i += ind) { if (a[i] > a[ind]) count = max(count, 1 + func(i)); } return dp[ind] = count; } int main() { int t; cin >> t; while (t--) { cin >> n; for (int i = 1; i < n + 1; i++) { cin >> a[i]; dp[i] = -1; } int maxi = 1; for (int i = 1; i < n + 1; i++) { maxi = max(maxi, 1 + func(i)); } cout << maxi << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } bool isPrime(long long n) { if (n < 2) return 0; if (n < 4) return 1; if (n % 2 == 0 or n % 3 == 0) return 0; for (long long i = 5; i * i <= n; i += 6) if (n % i == 0 or n % (i + 2) == 0) return 0; return 1; } long long modexpo(long long x, long long p) { long long res = 1; x = x % 1000000007; while (p) { if (p % 2) res = res * x; p >>= 1; x = x * x % 1000000007; res %= 1000000007; } return res; } int32_t smallestDivisor(long long n, long long temp) { for (long long i = 2; i <= temp; i++) { if (n % i == 0) return i; } return n; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; std::vector<long long> a(n + 1); a[0] = 100000000; for (long long i = 1; i < n + 1; i++) cin >> a[i]; long long max = 0; vector<long long> max_v(n + 1, 1); for (long long i = n; i > 0; i--) { for (long long j = i * 2; j < n + 1; j = j + i) { if (a[i] < a[j]) { max_v[i] = (max_v[i] > max_v[j] + 1 ? max_v[i] : max_v[j] + 1); } } } for (long long i = 1; i < n + 1; i++) if (max < max_v[i]) max = max_v[i]; cout << max << endl; } }
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&) { return *this; } }; long double eps = (long double)1 / 1e6; long long inf = INT_MAX, mod2 = 998244353, mod1 = 1e9 + 7; long long sqr(long long a) { return a * a; } long long qb(long long a) { return a * a * a; } long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); } long long binpow(long long a, long long b, long long mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; } long long binmult(long long a, long long b, long long mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; } const long long R = 1e4; const long long tx[4] = {0, 0, -1, 1}; const long long ty[4] = {-1, 1, 0, 0}; const char rev_to[4] = {'E', 'W', 'N', 'S'}; const long long N = 5 * 1e5 + 1; const pair<long long, long long> c = make_pair(-1, -1); bool ok = 0; signed main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); ; long long t; cin >> t; while (t--) { long long n, k; cin >> n; vector<long long> a(n + 1); vector<long long> dp(n + 2, 1); for (long long i = 1; i <= n; i++) { cin >> a[i]; } long long ans = -inf; for (long long i = 1; i <= n; i++) { for (long long j = 2 * i; j <= n; j += i) { if (a[j] > a[i]) { dp[j] = max(dp[j], dp[i] + (a[j] > a[i])); } } ans = max(ans, dp[i]); } ans = *(max_element(dp.begin(), dp.end())); cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 2000005; const long long mod = 1000000007; signed main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> a(n + 1); for (long long i = 1; i <= n; i++) cin >> a[i]; vector<long long> dp(n + 1); for (long long i = 1; i <= n; i++) dp[i] = 1; for (long long i = 1; i <= n; i++) for (long long j = 2 * i; j <= n; j += i) if (a[i] < a[j]) dp[j] = max(dp[j], dp[i] + 1); long long ans = 0; for (long long i = 1; i <= n; i++) ans = max(dp[i], ans); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int t, n, a[100005], dp[100005], ans; int main() { cin >> t; while (t--) { cin >> n; ans = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; dp[i] = 1; } for (int i = 1; i <= n; i++) { for (int j = i + i; j <= n; j += i) { if (a[j] > a[i]) dp[j] = max(dp[j], dp[i] + 1); } ans = max(ans, dp[i]); } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; map<long long, long long> m; int main() { long long t, n; cin >> t; while (t--) { cin >> n; long long a[n]; long long i, j, k; for (i = 1; i <= n; i++) { cin >> a[i]; m[i] = 1; } long long minu, tumu; for (i = 1; i <= n; i++) { for (j = i * 2; j <= n; j += i) { if (a[i] < a[j]) { m[j] = max(m[j], m[i] + 1); } } } minu = 0; for (int i = 1; i <= n; i++) { minu = max(minu, m[i]); } cout << minu << endl; } }
#include <bits/stdc++.h> using namespace std; int t, i, j, k, v[100008], n, contmax, lis[100005]; int main() { cin >> t; while (t--) { cin >> n; for (i = 1; i <= n; i++) cin >> v[i]; contmax = 1; for (i = n; i >= 1; i--) { lis[i] = 1; for (j = i + i; j <= n; j = j + i) if (v[i] < v[j]) lis[i] = max(lis[i], lis[j] + 1), contmax = max(contmax, lis[i]); } cout << contmax << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> void printer(char *name, T value) { cout << "name: " << name << "\tvalue: " << value << "\n"; } int32_t main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long T; cin >> T; long long n, a1, an, t; long long dp[100005], v[100005]; while (T--) { cin >> n; for (long long i = 0; i < n; i++) { cin >> v[i + 1]; dp[i + 1] = 1; } for (long long m = 1; m < n; m++) { for (long long j = 2; j < (n / m) + 1; j++) { if (v[m] < v[m * j]) dp[m * j] = max(dp[m * j], dp[m] + 1); } } cout << *max_element(dp + 1, dp + n + 1) << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 500005; int n, a[MAXN], f[MAXN]; int main() { int T; cin >> T; while (T--) { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) f[i] = 1; for (int i = 1; i <= n; i++) for (int j = i * 2; j <= n; j += i) if (a[i] < a[j]) f[j] = max(f[j], f[i] + 1); int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, f[i]); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, s[100010]; long long dp[100010], ans = 1; void code() { cin >> n; for (int i = 1; i < n + 1; i++) cin >> s[i]; memset(dp, 0, (n + 1) * sizeof(dp[0])); ans = 1; dp[1] = 1; for (int i = 2; i < n + 1; i++) if (s[i] > s[1]) dp[i] = 1; for (int i = 2; i < n + 1; i++) { dp[i]++; int x = 2; while (i * x <= n) { if (s[i * x] > s[i]) dp[i * x] = max(dp[i * x], dp[i]); x++; } ans = max(ans, dp[i]); } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while (t--) { code(); } }
#include <bits/stdc++.h> using namespace std; int a[100010], dp[100010]; int main() { int t; cin >> t; while (t--) { memset(dp, 0, sizeof(0)); int n; cin >> n; int ans = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; dp[i] = 1; } for (int j = 1; j <= n; j++) { for (int i = 2 * j; i <= n; i += j) { if (a[j] < a[i]) dp[i] = max(dp[j] + 1, dp[i]); } ans = max(ans, dp[j]); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long exp(long long n, long long m, long long md) { long long a = 1; while (m > 0) { if (m & 1) a = (a * n % md) % md; m /= 2; n = (n * n) % md; } return a % md; } void disp(vector<long long> v) { for (auto u : v) cout << u << " "; cout << "\n"; } long long gcd2(long long a, long long b) { return b ? gcd2(b, a % b) : a; } bool naiveprime(long long n) { if (n < 2) return false; for (long long x = 2; x * x <= n; x++) { if (n % x == 0) return false; } return true; } bool check_composite_for_prime_function(long long n, long long a, long long d, int s) { long long x = exp(a, d, n); if (x == 1 || x == n - 1) return false; for (int r = 1; r < s; ++r) { x = x * x % n; x %= n; if (x == n - 1) return false; } return true; } bool prime(long long n, int iter = 5) { if (n < 4) return n == 2 || n == 3; if (!(n & 1)) return false; int s = 0; long long d = n - 1; while (!(d & 1)) { d >>= 1; s++; } for (int a : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}) { if (n == a) return true; if (check_composite_for_prime_function(n, a, d, s)) return false; } return true; } const int NPR = 10000000; int lp[NPR + 1]; vector<int> pr; void prfac(int n = NPR) { if (n > NPR) return; long long i; for (i = 0; i < n + 5; i++) lp[i] = 0; for (i = 2; i <= n; ++i) { if (lp[i] == 0) { lp[i] = i; pr.push_back(i); } for (int j = 0; j < (int)pr.size() && pr[j] <= lp[i]; ++j) { long long a = i * pr[j]; if (a <= n) lp[a] = pr[j]; } } } long long a[100001]; void go1() { long long n; cin >> n; long long i, j, k; for (i = 1; i < n + 1; i++) cin >> a[i]; long long ans[n + 1]; ans[n] = 1; long long mxx = 1; for (i = n - 1; i >= 1; i--) { ans[i] = 1; j = 2; long long mx = 0; while (j * i <= n) { if (a[j * i] > a[i]) { if (mx < ans[j * i]) mx = ans[j * i]; } j++; } ans[i] += mx; if (mxx < ans[i]) mxx = ans[i]; } cout << mxx << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); chrono::high_resolution_clock::time_point start = chrono::high_resolution_clock::now(); long long tt = 1; cin >> tt; long long t = tt; cout << fixed << setprecision(10); while (tt--) { go1(); } chrono::high_resolution_clock::time_point end = chrono::high_resolution_clock::now(); long double time_spent = (chrono::duration_cast<chrono::duration<long double> >(end - start)) .count(); cerr << time_spent << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10, inf = 1e9; int s[maxn], f[maxn]; int main() { int T, n; for (scanf("%d", &T); T; T--) { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &s[i]), f[i] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j * j <= i; j++) if (i % j == 0) { if (s[i] > s[j]) f[i] = max(f[i], f[j] + 1); if (s[i] > s[i / j]) f[i] = max(f[i], f[i / j] + 1); } } int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, f[i]); printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1], dp[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) dp[i] = 1; dp[1] = 1; for (int i = 1; i <= n; i++) { for (int j = 2 * i; j <= n; j += i) if (a[j] > a[i]) dp[j] = max(dp[j], dp[i] + 1); } int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, dp[i]); cout << ans << '\n'; } }
#include <bits/stdc++.h> using namespace std; int main() { long long int tstt; cin >> tstt; for (long long int duh = 0; duh < tstt; duh++) { long long int n; cin >> n; long long int s[n + 1]; for (long long int i = 1; i < n + 1; i++) cin >> s[i]; long long int dp[n + 1]; for (long long int i = 1; i < n + 1; i++) dp[i] = 0; long long int ans = 1; long long int maxVal = 0; for (long long int val = 1; val < n + 1; val++) { maxVal = 0; for (long long int i = 1; i * i <= val; i++) { if (val % i == 0) { if (i * i == val && s[i] < s[val]) { maxVal = max(dp[i], maxVal); } if (i * i != val) { if (s[i] < s[val]) { maxVal = max(dp[i], maxVal); } if (s[val / i] < s[val]) { maxVal = max(maxVal, dp[val / i]); } } } } dp[val] = maxVal + 1; ans = max(ans, dp[val]); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); long long int t; cin >> t; while (t--) { long long int n; long long int ans = 0; cin >> n; vector<long long int> dp(n + 1); vector<long long int> v(n + 1); for (int i = 1; i <= n; i++) { cin >> v[i]; } for (int i = 1; i <= n; i++) { for (int j = i * 2; j <= n; j += i) { if (v[i] < v[j]) { dp[j] = max(dp[i] + 1, dp[j]); if (dp[j] > ans) ans = dp[j]; } } } cout << ans + 1 << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int ans, a[N], f[N], T, t, n; int main() { scanf("%d", &T); while (T--) { ans = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) f[i] = 1; ans = 1; for (int i = 2; i <= n; i++) { t = sqrt(i); for (int j = 1; j <= t; j++) if (i % j == 0) { if (a[i] > a[j]) f[i] = max(f[i], f[j] + 1); if (a[i] > a[i / j] && j != 1) f[i] = max(f[i], f[i / j] + 1); } if (f[i] > ans) ans = f[i]; } printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1000000007, LIM = 4294967295; long long int n, m, a, b, c, d, q, k, tr, summ, ans, minx, maxx, mass[300000], mass1[300000], mass2[300000]; string s; set<long long int> r, g, bb, all; set<long long int> myset; vector<long long int> myvec; vector<vector<long long int>> myvecvec; queue<long long int> myq; map<long long int, multimap<long long int, pair<long long int, long long int>>> mymap; int compare(const void* a, const void* b) { return -((*(long long int*)a) - (*(long long int*)b)); }; long long int gcd(long long int a, long long int b) { while (b != 0) { long long int t = b; b = a % b; a = t; } return a; } long long int gcdex(long long int a, long long int b, long long int& x, long long int& y) { if (a == 0) { x = 0; y = 1; return b; } long long int x1, y1; long long int d = gcdex(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } long long int NOK(long long int n1, long long int n2) { return n1 * n2 / gcd(n1, n2); } long long int bin_pow(long long int base, long long int p) { if (p == 1) { return base % MOD; } if (p == 0) { return 1; } if (p % 2 == 0) { long long int t = bin_pow(base, p / 2) % MOD; return t * t % MOD; } else { return bin_pow(base, p - 1) * base % MOD; } } long long int inverse_element(long long int x) { return bin_pow(x, MOD - 2); } long long int divide(long long int a, long long int b) { return a * inverse_element(b) % MOD; } int main() { ios::sync_with_stdio(0); cin.tie(); cin >> q; while (q--) { cin >> a; for (long long int i = 1; i < a + 1; i++) { cin >> mass[i]; mass1[i] = 1; } b = 0; for (long long int i = 1; i < a + 1; i++) { for (long long int j = i * 2; j <= a; j += i) { if (mass[j] > mass[i]) { mass1[j] = max(mass1[j], mass1[i] + 1); } } b = max(b, mass1[i]); } cout << b << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); } long long Power(long long a, long long b, long long p) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % p; a = a * a % p; b >>= 1; } return ans; } bool isPrime(long long num) { if (num == 2 || num == 3) return true; if (num % 6 != 1 && num % 6 != 5) return false; long long t = sqrt((double)num); for (long long i = 5; i <= t; i += 6) if (num % i == 0 || num % (i + 2) == 0) return false; return true; } bool isRunyear(int year) { if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { return true; } else { return false; } } string add(string s1, string s2) { if (s1.length() < s2.length()) { string temp = s1; s1 = s2; s2 = temp; } int i, j; for (i = s1.length() - 1, j = s2.length() - 1; i >= 0; i--, j--) { s1[i] = char(s1[i] + (j >= 0 ? s2[j] - '0' : 0)); if (s1[i] - '0' >= 10) { s1[i] = char((s1[i] - '0') % 10 + '0'); if (i) s1[i - 1]++; else s1 = '1' + s1; } } return s1; } long long n, m, i, j, k, t; const long long INF = 1e5 + 10; string s, s1, s2; long long a[200000]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); while (cin >> k) { while (k--) { cin >> n; map<long long, long long> mm; long long sum = 1; for (i = 1; i <= n; i++) { cin >> a[i]; mm[i] = 1; } for (i = 1; i <= n; i++) { for (j = 2; j * i <= n; j++) { if (a[j * i] > a[i]) { mm[j * i] = max(mm[j * i], mm[i] + 1); sum = max(sum, mm[i * j]); } } } cout << sum << endl; } } }
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; long long int a[n + 1]; vector<long long int> v(n + 1, 1); for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { for (int j = i * 2; j <= n; j += i) if (a[i] < a[j]) v[j] = max(v[j], v[i] + 1); } auto it = max_element(v.begin(), v.end()); cout << *it << '\n'; } return 0; }
#include <bits/stdc++.h> const int INF = 1e9; using namespace std; vector<int> st; void printDivisors(int n) { st.clear(); for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) st.push_back(i); else { st.push_back(i), st.push_back(n / i); } } } return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<int> ary(n + 1); for (int i = 1; i <= n; i++) cin >> ary[i]; vector<int> dp(n + 1, 1); dp[0] = 0; for (int j = 1; j <= n; j++) { for (int i = 1; i <= sqrt(j); i++) { if (j % i == 0) { if (j / i == i) { if (ary[i] < ary[j]) { dp[j] = max(dp[j], dp[i] + 1); } } else { if (ary[i] < ary[j]) { dp[j] = max(dp[j], dp[i] + 1); } if (ary[j / i] < ary[j]) { dp[j] = max(dp[j], dp[j / i] + 1); } } } } } cout << *max_element(dp.begin(), dp.end()) << endl; } }
#include <bits/stdc++.h> using namespace std; long long n, m, i, j, k, s = 0, l, t; int main() { cin >> t; while (t--) { cin >> n; long long a[n + 5], b[n + 5]; memset(b, 0, sizeof(b)); for (i = 1; i <= n; i++) cin >> a[i]; long long mn = 1; for (i = 1; i <= n; i++) { if (b[i] == 0) b[i] = 1; for (j = 2 * i; j <= n; j += i) { if (a[j] > a[i]) { b[j] = max(b[j], b[i] + 1); mn = max(mn, b[j]); } } } cout << mn << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = (1e9) + 7; const double pi = acos(-1); long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } void solve() { int n, i, j, a[100005]; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; } int ans = 1; vector<int> dp(n + 1, 0); for (i = 1; i <= n; i++) { for (j = 1; j <= sqrt(i); j++) { if (i % j == 0) { if (a[i] > a[j]) { dp[i] = max(dp[j] + 1, dp[i]); } if (a[i] > a[i / j]) { dp[i] = max(dp[i / j] + 1, dp[i]); } } } if (dp[i] == 0) dp[i] = 1; ans = max(ans, dp[i]); } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t = 1; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int test; cin >> test; while (test--) { int n; cin >> n; int arr[n + 1]; int dp[n + 1]; for (int i = 1; i <= n; i++) { dp[i] = 1; } for (int i = 1; i <= n; i++) { cin >> arr[i]; } for (int i = 1; i <= n; i++) { for (int j = (2 * i); j <= n; j += i) { if (arr[i] < arr[j]) { dp[j] = max(dp[i] + 1, dp[j]); } } } int maxm = 1; for (int i = 1; i <= n; i++) { maxm = max(maxm, dp[i]); } cout << maxm << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long MAX = 10005; const long long mod = 1.0e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n, m, i, j, k, x, y, z; cin >> n; long long arr[n + 1]; for (i = 1; i <= n; i++) { cin >> arr[i]; } long long lis[n + 1]; memset(lis, 0, sizeof(lis)); lis[1] = 1; for (i = 2; i <= n; i++) { lis[i] = 1; vector<long long> v; for (j = 1; j <= sqrt(i); j++) { if (i % j == 0) { v.push_back(j); if (j != (i / j) && j != 1) { v.push_back(i / j); } } } for (j = 0; j < v.size(); j++) { if (arr[i] > arr[v[j]] && lis[i] < lis[v[j]] + 1) lis[i] = lis[v[j]] + 1; } } long long maxx = 0; for (i = 1; i <= n; i++) { maxx = max(maxx, lis[i]); } cout << maxx << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> vec(1, 0); vector<int> dp(1, 0); int n; int solve(int i) { if (i == 1) { return 1; } if (dp[i]) return dp[i]; int res = 1; for (int idx = 1; idx * idx <= i; idx++) { if (i % idx == 0) { if (vec[i] > vec[idx]) { res = max(res, 1 + solve(idx)); } if (idx > 1 && vec[i] > vec[i / idx]) { res = max(res, 1 + solve(i / idx)); } } } dp[i] = res; return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); vec.resize(100010); dp.assign(100010, 0); int t; cin >> t; for (int i = 0; i < t; i++) { cin >> n; fill_n(dp.begin(), n + 5, 0); for (int i = 1; i <= n; i++) { cin >> vec[i]; } int res = 1; for (int j = 1; j <= n; j++) { res = max(res, solve(j)); } cout << res << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; inline long long add(long long a, long long b) { a = (a + b); if (a >= 1000000007) a -= 1000000007; return a; } inline long long sub(long long a, long long b) { a = a - b; if (a < 0) a += 1000000007; return a; } inline long long mul(long long a, long long b) { a = (a * b) % 1000000007; return a; } const long long N = 1e6 + 5; vector<long long> arr1(N, 0); void pre() { for (long long i = 2; i < N; i++) { if (arr1[i] == 0) { for (long long j = i; j < N; j += i) { if (arr1[j] == 0) arr1[j] = i; } } } } void mymain() { long long n; cin >> n; vector<long long> arr(n); for (long long& i : arr) cin >> i; long long ans = 1; vector<long long> dp(n + 1, 1); for (long long i = 1; i <= n; i++) { for (long long j = 2; j * i <= n; j++) { long long k = j * i; if (arr[k - 1] > arr[i - 1]) { dp[k] = max(dp[k], dp[i] + 1); } } } for (long long i : dp) ans = max(i, ans); cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long t = 1; cin >> t; pre(); for (long long tt = 0; tt < t; tt++) { mymain(); } return 0; }
#include <bits/stdc++.h> using namespace std; long long int dp[10006]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int arr[n + 1], dp[n + 1]; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int i = 1; i <= n; i++) dp[i] = 1; for (int i = 1; i <= n; i++) { for (int j = i * 2; j <= n; j += i) { if (arr[i] < arr[j]) dp[j] = max(dp[j], dp[i] + 1); } } int count = 0; for (int i = 1; i <= n; i++) { count = max(count, dp[i]); } cout << count << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 2; long long n, arr[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long t; cin >> t; while (t--) { cin >> n; for (long long i = 1; i <= n; i++) cin >> arr[i]; long long dp[N], ans = 1; for (long long i = 0; i <= n; i++) dp[i] = 1; for (long long i = 1; i <= n; i++) { for (long long j = 2 * i; j <= n; j += i) if (arr[j] > arr[i]) dp[j] = max(dp[j], dp[i] + 1), ans = max(ans, dp[j]); } cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") void testcase() { long long n; cin >> n; vector<long long> a(n + 1); for (long long i = 1; i <= n; i++) cin >> a[i]; vector<long long> dp(n + 1, 1); for (long long i = 2; i <= n; i++) { for (long long j = 1; j * j <= i; j++) { if (i % j == 0 and a[j] < a[i]) dp[i] = max(dp[i], dp[j] + 1); if (i % (i / j) == 0 and a[i / j] < a[i]) dp[i] = max(dp[i], dp[i / j] + 1); } } long long ans = *(max_element(dp.begin(), dp.end())); cout << ans; } signed main() { ios::sync_with_stdio(false), cin.tie(NULL); long long t = 1; cin >> t; for (long long i = 1; i <= t; i++) { testcase(); cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 50; int a[maxn], dp[maxn]; void solve() { int n; scanf("%d", &n); int ans = 0; for (int i = 1; i <= n; i++) scanf("%d", &a[i]), dp[i] = 1; for (int i = 2; i <= n; i++) { for (int j = 1; j * j <= n; j++) { if (i % j == 0) { if (a[i] > a[j]) dp[i] = max(dp[i], dp[j] + 1); if (a[i] > a[i / j]) dp[i] = max(dp[i], dp[i / j] + 1); } } } for (int i = 1; i <= n; i++) ans = max(ans, dp[i]); printf("%d\n", ans); } int main() { int t; scanf("%d", &t); while (t--) solve(); }
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; inline int read() { int x = 0, w = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); } while (c <= '9' && c >= '0') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); } return w == 1 ? x : -x; } int a[1000005], dp[1000005]; int main() { int T = read(); while (T--) { int n = read(), ans = 0; for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 1; i <= n; i++) dp[i] = 1; for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { if (a[j] > a[i]) dp[j] = max(dp[j], dp[i] + 1); } } for (int i = 1; i <= n; i++) ans = max(ans, dp[i]); printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; class comp { public: bool operator()(int& a, int& b) { return a > b; } }; bool comp1(pair<int, int> a, pair<int, int> b) { return (a.second < b.second); } void solve() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v(n + 1); for (int i = 1; i <= n; i++) { cin >> v[i]; } vector<int> dp(n + 1, 1); for (int i = 1; i <= n; i++) { for (int j = 2 * i; j <= n; j += i) { if (v[i] < v[j]) { dp[j] = max(dp[i] + 1, dp[j]); } } } int res = INT32_MIN; for (int i = 1; i <= n; i++) { res = max(res, dp[i]); } cout << res << '\n'; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") #pragma GCC target("avx2") using namespace std; int ret(int *a, int n) { int lis[n + 1]; for (int i = 1; i <= n; i++) lis[i] = 1; for (int i = 1; i <= n; i++) { for (int j = i * 2; j <= n; j += i) { if (a[j] > a[i] && lis[j] < lis[i] + 1) lis[j] = lis[i] + 1; } } return *max_element(lis + 1, lis + n + 1); } int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; cout << ret(a, n) << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int a[N], f[N]; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int main() { int T; cin >> T; while (T--) { int n, k; scanf("%d", &n); memset(a, 0, sizeof a); for (int i = 1; i <= n; i++) f[i] = 1; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) for (int j = 2 * i; j <= n; j += i) if (a[i] < a[j]) f[j] = max(f[j], f[i] + 1); int res = 0; for (int i = 1; i <= n; i++) res = max(res, f[i]); printf("%d\n", res); } return 0; }
#include <bits/stdc++.h> using namespace std; long long a[800005]; long long dp[800005]; signed main() { ios::sync_with_stdio(0); cin.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; dp[i] = 1; } for (long long i = 1; i <= n; i++) { for (long long j = i * 2; j <= n; j += i) { if (a[j] > a[i]) { dp[j] = max(dp[j], dp[i] + 1); } } } long long ans = 1; for (long long i = 1; i <= n; i++) { ans = max(ans, dp[i]); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433; const int mod = 1000000007; const long long inf = 3e18; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n; cin >> n; vector<pair<long long, long long>> a(n); map<long long, long long> aa; for (long long i = 0; i < n; i++) { cin >> a[i].first; a[i].second = i + 1; aa[i] = a[i].first; } sort(a.begin(), a.end()); vector<long long> b(n); for (long long i = 0; i < n; i++) { b[i] = a[i].second; } vector<long long> fans(n); map<long long, long long> mp, k; for (long long i = 0; i < n; i++) { long long h = b[i]; long long ans = 1; for (long long j = 1; j <= sqrt(h); j++) { if (h % j == 0) { if (mp[j] != 0) { if (aa[j - 1] < aa[h - 1]) ans = max(ans, mp[j] + 1); } if (mp[h / j] != 0) { if (aa[h / j - 1] < aa[h - 1]) ans = max(ans, mp[h / j] + 1); } } } mp[h] = ans; fans[i] = ans; } sort(fans.begin(), fans.end()); cout << fans[n - 1] << "\n"; } }
#include <bits/stdc++.h> using namespace std; int nCr(int n, int r) { int res = 1; if (n < r) return -1; r = min(r, n - r); for (int i = 0; i < r; i++) { res *= (n - i); res /= (i + 1); } return res; } bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } void solve() { long long n; cin >> n; vector<long long> v(n + 1); for (int i = 0; i < n; i++) cin >> v[i + 1]; vector<long long> a(n + 1, 1); for (int i = 1; i <= n; i++) { for (int j = 2 * i; j <= n; j += i) { if (v[i] < v[j]) a[j] = max(a[j], a[i] + 1); } } cout << *max_element(a.begin(), a.end()) << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cout << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&) { return *this; } }; using ll = long long; using ld = long double; const ll MOD = 1e9l + 7; const ll INF = 1e18l + 5; inline ll add(ll a, ll b) { return (a % MOD + b % MOD) % MOD; } inline ll sub(ll a, ll b) { return (a % MOD - b % MOD + MOD) % MOD; } inline ll mult(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; } inline ll power(ll a, ll b) { a %= MOD; ll r = 1; while (b) { if (b & 1) r = mult(r, a); a = mult(a, a); b >>= 1; } return r; } vector<ll> a(100010); vector<ll> dp(100010); ll n; ll func(ll ind) { if (dp[ind] != -1) return dp[ind]; if (ind > n) return 0; ll ma = 0; for (ll i = 2 * ind; i <= n; i += ind) { if (a[i] > a[ind]) ma = max(ma, 1 + func(i)); } return dp[ind] = ma; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed; ll t; cin >> t; while (t--) { cin >> n; for (ll i = 1; i <= n; ++i) { cin >> a[i]; dp[i] = -1; } ll ma = 1; for (ll i = 1; i <= n; ++i) { ma = max(ma, 1 + func(i)); } cout << ma << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int64_t a[n]; for (int i = 0; i < n; ++i) cin >> a[i]; int64_t dp[n]; int64_t ans = 0; for (int i = n - 1; i >= 0; --i) { dp[i] = 1; for (int j = 2 * i + 1; j < n; ++j) { if (a[j] > a[i]) dp[i] = max(dp[i], dp[j] + 1); j += i; } ans = max(ans, dp[i]); } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; void chmax(int &x, int y) { x = max(x, y); } signed main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> s(n + 1, 0); for (int i = 1; i <= n; ++i) cin >> s[i]; vector<int> d(n + 1, 1); for (int i = 1; i <= n; ++i) { for (int j = 2 * i; j <= n; j += i) { if (s[j] > s[i]) chmax(d[j], d[i] + 1); } } cout << *max_element(d.begin(), d.end()) << '\n'; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int a[n]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); int dp[n + 1]; for (int i = 0; i < n + 1; i++) dp[i] = 1; for (int i = n - 1; i > 0; i--) { int j = 2; while (i * j <= n) { if (a[i - 1] < a[i * j - 1]) { if (dp[i * j] + 1 > dp[i]) dp[i] = dp[i * j] + 1; } j += 1; } } int maxans = 0; for (int i = 1; i <= n; i++) { if (dp[i] > maxans) maxans = dp[i]; } printf("%d", maxans); printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; double pi = 2 * acos(0.0); const int INF = 1e9 + 7; long long gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long int a, long long int b) { return (a / gcd(a, b)) * b; } long long int power(long long int x, long long int y) { long long int res = 1; x = x; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } long long int nCrModp(long long int n, long long int r, long long int p) { if (r > n - r) r = n - r; long long int C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (long long int i = 1; i <= n; i++) { for (int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p; } return C[r]; } vector<bool> prime(10000009, true); vector<int> listof; void sieve() { prime[1] = false; for (int i = 2; i <= sqrt(1000009); i++) { if (prime[i] == true) { for (int j = i * i; j < 10000009; j += i) { prime[j] = false; } } } for (int i = 2; i < 10000009; i++) { if (prime[i] == true) { listof.push_back(i); } } } void WetPitch() { long long int n; vector<long long int> v(100005); cin >> n; for (int i = 1; i < n + 1; i++) { cin >> v[i]; } long long int dp[100005]; long long int ans = 1; for (int i = 1; i <= n; i++) { dp[i] = 1; } for (int i = 1; i <= n; i++) { for (int j = 2 * i; j <= n; j += i) { if (v[i] < v[j]) { dp[j] = max(dp[j], dp[i] + 1); } ans = max(ans, dp[j]); } } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int tst; tst = 1; cin >> tst; int p = 1; while (tst--) { WetPitch(); } return 0; }
#include <bits/stdc++.h> using namespace std; int a[100004]; int dp[100004]; int n; int fun(int idx) { if (idx > n) { return 0; } if (dp[idx] != -1) { return dp[idx]; } int cou = 0; for (int i = 2 * idx; i <= n; i += idx) { if (a[i] > a[idx]) { cou = max(cou, 1 + fun(i)); } } return dp[idx] = cou; } int main() { int t; cin >> t; while (t--) { int cnt = 1; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; dp[i] = -1; } for (int i = 1; i <= n; i++) { cnt = max(cnt, 1 + fun(i)); } cout << cnt << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; int a[n + 1]; int f[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n; i++) { f[i] = 1; } for (int i = 1; i <= n; i++) { for (int j = i * 2; j <= n; j += i) { if (a[i] < a[j]) { f[j] = max(f[j], f[i] + 1); } } } int ans = 0; for (int i = 1; i <= n; i++) { ans = max(ans, f[i]); } cout << ans << "\n"; } }
#include <bits/stdc++.h> using namespace std; const long mod = 1e9 + 7; long long min(long long a, long long b) { if (a < b) return a; return b; } long long max(long long a, long long b) { if (a > b) return a; return b; } bool cmp(pair<long long, long long> &a, pair<long long, long long> &b) { if (a.first == b.first) { return a.second < b.second; } return a.first < b.first; } void solve() { long long n; cin >> n; vector<long long> a(n + 1); for (long long i = 0; i < n; i++) { int q; cin >> q; a[i + 1] = q; } vector<long long> ans(n + 1, 1); for (long long i = 1; i < n + 1; i++) { for (int j = 2 * i; j <= n; j += i) { if (a[j] > a[i]) { ans[j] = max(ans[j], ans[i] + 1); } } } cout << *max_element(ans.begin(), ans.end()) << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; int i = 1; while (t--) { solve(); i++; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, s[100010]; long long dp[100010], ans; void code() { cin >> n; for (int i = 1; i < n + 1; i++) cin >> s[i]; memset(dp, 0, (n + 1) * sizeof(dp[0])); ans = 1; for (int i = 1; i < n + 1; i++) { dp[i]++; int x = 2; while (i * x <= n) { if (s[i * x] > s[i]) dp[i * x] = max(dp[i * x], dp[i]); x++; } ans = max(ans, dp[i]); } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while (t--) { code(); } }
#include <bits/stdc++.h> using namespace std; string out; long long int T; int S[200000]; int N, A; void process() { cin >> N, A = 0; int DP[200000] = {0}; for (int i = 1; i <= N; i++) cin >> S[i]; for (int i = 1; i <= N; i++) { A = max(A, DP[i] = max(DP[i], 1)); for (int j = 2 * i; j <= N; j += i) if (S[j] > S[i]) DP[j] = max(DP[j], DP[i] + 1); } out += to_string(A) + "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> T; for (int t = 1; t <= T; t++) process(); cout << out; return 0; }
#include <bits/stdc++.h> using namespace std; long long const INF = 1e18; long long const MOD = 998244353; vector<long long> pr; void solve() { long long n; cin >> n; vector<long long> s(n + 1), cnt(n + 1, 1); for (long long i = 1; i <= n; i++) { cin >> s[i]; } for (long long i = 1; i <= n; ++i) for (long long j = i * 2; j <= n; j += i) { if (s[i] < s[j]) cnt[j] = max(cnt[j], cnt[i] + 1); } cout << *max_element(cnt.begin(), cnt.end()); } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(16); long long t = 1; long long n = 1e6; vector<char> prime(n + 1, true); prime[0] = prime[1] = false; for (long long i = 2; i <= n; ++i) if (prime[i]) if (i * 1ll * i <= n) for (long long j = i * i; j <= n; j += i) prime[j] = false; for (long long i = 0; i < n; i++) { if (prime[i]) { pr.push_back(i); } } cin >> t; while (t--) { solve(); cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t, n; cin >> t; while (t--) { cin >> n; vector<long long> arr(n + 1), dp(n + 1, 1); cin >> arr[1]; bool ok = 1; for (auto i = 2; i <= n; ++i) { cin >> arr[i]; if (arr[i] > arr[0]) ok = 0; } if (ok || n == 1) { cout << 1 << '\n'; continue; } long long ans = 0; for (auto i = 1; i <= n; ++i) { for (auto j = 2 * i; j <= n; j += i) { if (arr[i] < arr[j]) { dp[j] = max(dp[j], dp[i] + 1); } } } for (auto i = 1; i <= n; ++i) ans = max(ans, dp[i]); cout << ans << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 500005; inline int readint() { int res = 0; char c = 0; while (!isdigit(c)) c = getchar(); while (isdigit(c)) res = res * 10 + c - '0', c = getchar(); return res; } int n, a[MAXN], f[MAXN]; int main() { int T = readint(); while (T--) { n = readint(); for (int i = 1; i <= n; i++) a[i] = readint(); for (int i = 1; i <= n; i++) f[i] = 1; for (int i = 1; i <= n; i++) for (int j = i * 2; j <= n; j += i) if (a[i] < a[j]) f[j] = max(f[j], f[i] + 1); int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, f[i]); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t > 0) { t--; long long n, maxi = 1; cin >> n; vector<long long> ar(n + 1); vector<long long> res(n + 1, 1); for (long long i = 1; i <= n; i++) cin >> ar[i]; for (long long i = 1; i <= n; i++) { for (long long j = i * 2; j <= n; j += i) { if (ar[i] < ar[j]) { res[j] = max(res[j], res[i] + 1); } } } for (long long i = 1; i <= n; i++) { maxi = max(res[i], maxi); } cout << maxi << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; vector<long long> divisors[100005]; long long ans[100005]; long long ara[100005]; void refresh() {} int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t = 1, i, j; cin >> t; for (i = 1; i <= 100000; i++) { for (j = i; j <= 100000; j += i) { divisors[j].push_back(i); } } while (t--) { refresh(); long long n; cin >> n; for (i = 1; i <= n; i++) { cin >> ara[i]; ans[i] = 1; } ans[1] = 1; long long fin = 1; for (i = 1; i <= n; i++) { for (j = 0; j < divisors[i].size(); j++) { long long x = divisors[i][j]; if (ara[x] < ara[i]) { ans[i] = max(ans[i], ans[x] + 1); } } fin = max(ans[i], fin); } cout << fin << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> arr(n + 1); vector<int> dp(n + 1, 1); for (int i = 1; i <= n; ++i) { cin >> arr[i]; } for (int i = 1; i <= n; ++i) { for (int j = i * 2; j <= n; j += i) { if (arr[i] < arr[j]) { dp[j] = max(dp[j], dp[i] + 1); } } } cout << *max_element(dp.begin(), dp.end()) << endl; } }
#include <bits/stdc++.h> using namespace std; double eps = 1e-10; const int N = 1e5 + 10; int dp[N]; int a[N]; int main() { int t; scanf("%d", &t); while (t--) { 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; } int ans = 0; for (int i = 1; i <= n; i++) { for (int j = i + i; j <= n; j += i) { if (a[j] > a[i]) { dp[j] = max(dp[j], dp[i] + 1); } } ans = max(ans, dp[i]); } printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 4; int a[N], dp[N]; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t, b, c, x, y, k, i, ans, val, tot, res, pos, n; string s; cin >> t; while (t--) { cin >> n; for (i = 1; i <= n; ++i) { cin >> a[i]; dp[i] = 1; } ans = dp[1] = 1; for (i = 2; i <= n; ++i) { vector<int> vec; vec.push_back(i); for (k = 2; k <= sqrt(i); ++k) { if ((i % k) == 0) { vec.push_back(k); vec.push_back(i / k); } } for (auto u : vec) { val = i / u; if (a[val] < a[i]) dp[i] = max(dp[i], dp[val] + 1); } ans = max(ans, dp[i]); } cout << ans << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long MAXN = (long long)((1e5) + 100); long long gcd(long long a, long long b) { if (a == 0) return b; return gcd(b % a, a); } long long max(long long a, long long b) { if (a > b) return a; else return b; } long long min(long long a, long long b) { if (a < b) return a; else return b; } void pr(long long x) { cout << x; } void prl(long long x) { cout << x << "\n"; } long long cbrt(long long x) { long long lo = 1, hi = min(2000000ll, x); while (hi - lo > 1) { long long mid = (lo + hi) / 2; if (mid * mid * mid < x) { lo = mid; } else hi = mid; } if (hi * hi * hi <= x) return hi; else return lo; } const long long dx[4] = {-1, 1, 0, 0}; const long long dy[4] = {0, 0, -1, 1}; long long XX[] = {-1, -1, -1, 0, 0, 1, 1, 1}; long long YY[] = {-1, 0, 1, -1, 1, -1, 0, 1}; const long long N = (long long)(2 * 1e5 + 10); long long dp[100004]; long long n; long long a[100004]; long long func(long long ind) { if (ind > n) return 0; if (dp[ind] != -1) return dp[ind]; long long count = 0; for (long long i = ind; i <= n; i += ind) { if (a[i] > a[ind]) count = max(count, 1 + func(i)); } return dp[ind] = count; } signed main() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); long long T = 1; cin >> T; while (T--) { cin >> n; for (long long i = 1; i <= n; i++) { cin >> a[i]; dp[i] = -1; } long long maxi = 1; for (long long i = 1; i <= n; i++) { maxi = max(maxi, 1 + func(i)); } prl(maxi); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<int>; using PII = pair<int, int>; using db = double; template <class T> void PR_A(T a[], int n) { for (int i = (0); i < (n); i++) cout << a[i] << " "; cout << endl; } template <class T> void PR_V(vector<T> a) { for (T& _ : a) cout << _ << " "; cout << endl; } int _; int n; int s[100001]; int dp[100001]; int main() { for (scanf("%d", &_); _; _--) { scanf("%d", &n); for (int i = (0); i < (n); i++) scanf("%d", s + i); for (int i = (0); i < (n); i++) dp[i] = 1; int ans = 0; for (int i = (0); i < (n); i++) { ans = max(ans, dp[i]); int k = 2; while ((i + 1) * k < n + 1) { if (s[(i + 1) * k - 1] > s[i]) dp[(i + 1) * k - 1] = max(dp[(i + 1) * k - 1], dp[i] + 1); k++; } } printf("%d\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; const int MOD = (int)998244353; const int INF = (int)1e18; bool cmp(const pair<long long, long long>& a, const pair<long long, long long>& b) { return a.second < b.second; } void solve() { long long n, mx = 0; cin >> n; long long a[n + 1], b[n + 1]; for (long long i = 1; i < n + 1; i++) { cin >> a[i], b[i] = 1; } for (long long i = 1; i < n + 1; i++) { for (long long j = 2 * i; j <= n; j += i) { if (a[j] > a[i]) { b[j] = max(b[j], b[i] + 1); } } } for (long long i = 1; i < n + 1; i++) mx = max(mx, b[i]); cout << mx << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t = 1, m = 1; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> const int MOD = 1e9 + 7; using namespace std; bool sortcol(const vector<int>& v1, const vector<int>& v2) { return v1[1] < v2[1]; } long long int mod_pow(int a, int b, int M = MOD) { int res = 1; while (b) { if (b & 1) res = (res * a) % M; a = (a * a) % M; b >>= 1; } return res; } long long int ncr(long long int n, long long int r) { if (n == 1 || r == 0) return 1; if (r > n / 2) r = n - r; long long int ans = 1; for (long long int i = 1; i <= r; i++) { ans = ((ans * n) / i); n--; } return ans; } long long int ncrsum(long long int n, long long int r, long long int mod) { if (n == 1 || r == 0) return 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n, i1, i2, k, m, j, j1, a1, f, i31, i3, j2, i5, i4, i6, i7, i; long long int x, y; long long int total = 0, cnt = 0; long long int flag = 0; y = 0; long long int res, res1, ans, res2, q; ans = 0; res1 = 0, res = 0; long long int s1, s2, s3; s2 = 0; long long int sum = 0; s1 = 0; long long int k1, k2, k3, d; string s; vector<long long int> v; cin >> n; long long int arr[n + 1]; for (i = 1; i <= n; i++) cin >> arr[i]; if (n == 1) { cout << 1 << "\n"; continue; } vector<long long int> dpp(n + 1, 1); for (i = 1; i <= n; i++) { for (j = 1; j * j <= i; j++) { if (i % j == 0) { if (arr[j] < arr[i]) dpp[i] = max(dpp[i], 1 + dpp[j]); if (arr[i / j] < arr[i]) dpp[i] = max(dpp[i], 1 + dpp[i / j]); } } ans = max(ans, dpp[i]); } cout << ans << "\n"; } }
#include <bits/stdc++.h> using namespace std; long long int dp[10006]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; int arr[n + 1], dp[n + 1]; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int i = 1; i <= n; i++) dp[i] = 1; for (int i = 1; i <= n; i++) { for (int j = i * 2; j <= n; j += i) { if (arr[i] < arr[j]) dp[j] = max(dp[j], dp[i] + 1); } } cout << *max_element(dp + 1, dp + n + 1) << "\n"; } return 0; }
#include <bits/stdc++.h> template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << " : " << arg1 << "\n"; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } std::pair<int, int> operator+(std::pair<int, int> a, std::pair<int, int> b) { return {a.first + b.first, a.second + b.second}; } std::pair<long long, long long> operator+(std::pair<long long, long long> a, std::pair<long long, long long> b) { return {a.first + b.first, a.second + b.second}; } std::ostream& operator<<(std::ostream& out, std::pair<int, int> a) { out << a.first << " " << a.second << "\n"; return out; } std::ostream& operator<<(std::ostream& out, std::pair<long long, long long> a) { out << a.first << " " << a.second << "\n"; return out; } std::istream& operator>>(std::istream& in, std::pair<int, int>& a) { in >> a.first >> a.second; return in; } std::istream& operator>>(std::istream& in, std::pair<long long, long long>& a) { in >> a.first >> a.second; return in; } int pow(int x, int y) { int temp; if (y == 0) return 1; temp = pow(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } bool prime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } using namespace std; void solve() { long long i, n, c = 0, a, mx = -1, b; cin >> n; long long A[n + 10], Ans[n + 10], k; for (i = 1; i <= n; ++i) { cin >> A[i]; Ans[i] = 1; } for (i = 1; i <= n; ++i) { for (k = i + i; k <= n; k += i) { if (A[k] > A[i]) Ans[k] = max(Ans[k], Ans[i] + 1); } mx = max(Ans[i], mx); } cout << mx << "\n"; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> f(n + 1, 1); int max1 = 1; for (int i = 1; i <= n; i++) { for (int j = i * 2; j <= n; j += i) { if (a[i] < a[j]) { f[j] = max(f[j], f[i] + 1); max1 = max(max1, f[j]); } } } cout << max1 << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 2; const long long MN = -1e9; const long long mod = 998244353; const long long md = 998244353; int main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } int dp[n + 3]; for (int i = 0; i <= n; i++) { dp[i] = 1; } for (int i = 1; i <= n; i++) { for (int j = i * 2; j <= n; j += i) { if (a[i] < a[j]) { dp[j] = max(dp[j], dp[i] + 1); } } } int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, dp[i]); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n + 1); vector<int> b(n + 1, 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } int ans = 0; for (int i = 1; i <= n; i++) { int sum = 0; for (int j = 1; j * j <= i; j++) { if (i % j == 0) { if (a[i] > a[j]) { sum = max(sum, b[j]); } if (a[i] > a[i / j]) { sum = max(sum, b[i / j]); } } } b[i] = sum + 1; ans = max(ans, b[i]); } cout << ans << endl; } int main() { int t; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> PII; int dir[8][2] = {-1, 0, 1, 0, 0, -1, 0, 1, -1, -1, -1, 1, 1 - 1, 1, 1}; int sgn(double x) { if (fabs(x) < 1e-8) return 0; if (x < 0) return -1; else return 1; } long long qpow(long long a, long long b, long long m) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % m; a = a * a % m, b >>= 1; } return ans; } long long qpow(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a; a = a * a, b >>= 1; } return ans; } long long qmul(long long a, long long b, long long m) { long long res = 0; while (b > 0) { if (b & 1) res = (res + a) % m; a = (a + a) % m; b >>= 1; } return res; } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } long long inv(long long t, long long p) { return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p; } long long exgcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long r = exgcd(b, a % b, y, x); y -= (a / b) * x; return r; } long long inv1(long long a, long long p) { long long d, x, y; d = exgcd(a, p, x, y); return d == 1 ? (x % p + p) % p : -1; } mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); template <typename S, typename T> inline bool Min(S &a, const T &b) { return a > b ? a = b, true : false; } template <typename S, typename T> inline bool Max(S &a, const T &b) { return a < b ? a = b, true : false; } template <typename T> inline bool IsPri(T x) { if (x < 2) return false; for (T i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; } template <typename T> inline int BitCnt(T x) { int cnt = 0; while (x) ++cnt, x &= x - 1; return cnt; } template <typename T> inline int BitNum(T x) { int cnt = 0; while (x) ++cnt, x >>= 1; return cnt; } template <class T> void _sf(T &x) { cin >> x; } void _sf(int &x) { scanf("%d", &x); } void _sf(long long &x) { scanf("%lld", &x); } void _sf(double &x) { scanf("%lf", &x); } void _sf(char &x) { scanf(" %c", &x); } void _sf(char *x) { scanf("%s", x); } void sf() {} template <class T, class... U> void sf(T &head, U &...tail) { _sf(head); sf(tail...); } template <class T> void _pf(const T &x) { cout << x; } void _pf(const int &x) { printf("%d", x); } void _pf(const long long &x) { printf("%lld", x); } void _pf(const double &x) { printf("%.16f", x); } void _pf(const char &x) { putchar(x); } void _pf(const char *x) { printf("%s", x); } template <class T, class U> void _pf(const pair<T, U> &x) { pf(x.F); putchar(' '); pf(x.S); } template <class T> void _pf(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _pf(*i++)) if (i != x.cbegin()) putchar(' '); } void pf() {} template <class T, class... U> void pf(const T &head, const U &...tail) { _pf(head); putchar(sizeof...(tail) ? ' ' : '\n'); pf(tail...); } template <typename T> inline void read(T &x) { x = 0; static int p; p = 1; static char c; c = getchar(); while (!isdigit(c)) { if (c == '-') p = -1; c = getchar(); } while (isdigit(c)) { x = (x << 1) + (x << 3) + (c - 48); c = getchar(); } x *= p; } const bool IOS = false; const double PI = acos(-1); const double eps = 1e-8; const long long linf = 0x3f3f3f3f3f3f3f3f; const long long INV2 = 500000004; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const int maxn = 1e5 + 10; vector<int> d[maxn]; void init() { for (int i = 1; i < maxn; ++i) { for (int j = i; j < maxn; j += i) d[j].push_back(i); } } int dp[maxn], a[maxn]; void Main(); int main() { if (IOS) std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); Main(); 0; return 0; } void Main() { init(); int T; scanf("%d", &T); while (T--) { int n; sf(n); for (int i = 1; i <= n; ++i) sf(a[i]), dp[i] = 1; for (int i = 2; i <= n; ++i) { for (auto it : d[i]) { if (a[it] < a[i]) Max(dp[i], dp[it] + 1); } } int ans = 0; for (int i = 1; i <= n; ++i) Max(ans, dp[i]); pf(ans); } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> dp(n + 1, 1); int ans = 1; for (int i = 1; i <= n; i++) { for (int j = 2 * i; j <= n; j += i) { if (a[j] > a[i]) { dp[j] = max(dp[j], 1 + dp[i]); ans = max(ans, dp[j]); } } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int t; cin >> t; while (t--) { long long int n; cin >> n; vector<long long int> v(n + 1), dp(n + 1, 0); for (long long int i = 1; i <= n; i++) { cin >> v[i]; } dp[1] = 1; long long int ans = 1; for (long long int i = 2; i <= n; i++) { long long int x = 0; if (v[i] > v[1]) x++; for (long long int j = 2; j * j <= i; j++) { if (i % j == 0) { if (v[j] < v[i]) x = max(x, dp[j]); if (v[i / j] < v[i]) x = max(x, dp[i / j]); } } dp[i] = ++x; ans = max(ans, dp[i]); } cout << ans << endl; } return 0; }