이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#include <numeric>
#include <functional>
#include <chrono>
#include <cassert>
#include <bitset>
//#include <bit>
//#include <ranges>
//#include <numbers>
#define itn int
#define sacnf scanf
#define sz(a) ((int)((a).size()))
// printf("%.10f\n", ans);
using ll = long long;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 1e5 + 1, inf = 1e9;
void compress(int& n, vector<int>& v)
{
vector<int> tmp = v;
sort(tmp.begin(), tmp.end());
map<int, int> mp;
int num = 1;
for (int i = 1; i <= n; i++) if (mp.find(tmp[i]) == mp.end()) mp[tmp[i]] = num++;
for (int i = 1; i <= n; i++) v[i] = mp[v[i]];
}
int find_max(vector<int>& segtree, int l, int r, int u, int tl, int tr)
{
if (l > r) return 0;
if (tl > r || tr < l) return INT_MIN;
if (l <= tl && tr <= r) return segtree[u];
int tm = (tl + tr) >> 1;
return max(find_max(segtree, l, r, u * 2 + 1, tl, tm), find_max(segtree, l, r, u * 2 + 2, tm + 1, tr));
}
void modify(vector<int>& segtree, int id, int v, int u, int tl, int tr)
{
if (tl == tr) segtree[u] = v;
else
{
int tm = (tl + tr) >> 1;
if (id <= tm) modify(segtree, id, v, u * 2 + 1, tl, tm);
else modify(segtree, id, v, u * 2 + 2, tm + 1, tr);
segtree[u] = max(segtree[u * 2 + 1], segtree[u * 2 + 2]);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// . . . . . . .
// . . . . . . .
// . . . . . . .
// . . . . . . .
// . . . . . . .
// . . . . . . .
// . . . . . . .
int n, d;
cin >> n >> d;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) cin >> v[i];
compress(n, v);
int len = 1;
while (len <= n) len <<= 1;
vector<vector<int>> segtrees_rows(n + 1, vector<int>(len << 1));
vector<vector<int>> segtrees_cols(n + 1, vector<int>(len << 1));
for (int i = 1; i <= n; i++)
{
int num = v[i];
int ans = 1;
for (int j = i - 1; j >= max(1, i - d); j--) ans = max(ans, 1 + find_max(segtrees_rows[j], 1, num - 1, 0, 0, len - 1));
ans = max(ans, find_max(segtrees_cols[num], 1, i - 1, 0, 0, len - 1));
modify(segtrees_rows[i], num, ans, 0, 0, len - 1);
modify(segtrees_cols[num], i, ans, 0, 0, len - 1);
for (int j = num + 1; j <= n; j++)
{
ans = find_max(segtrees_cols[j], 1, i - 1, 0, 0, len - 1);
modify(segtrees_rows[i], j, ans, 0, 0, len - 1);
modify(segtrees_cols[j], i, ans, 0, 0, len - 1);
}
}
cout << find_max(segtrees_rows[n], 1, n, 0, 0, len - 1);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |