이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <random>
#include <chrono>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 500005;
int n, d;
int a[N];
int par[N], sz[N], mn[N];
void init_dsu()
{
for (int i = 1; i <= n; i++)
{
par[i] = i;
mn[i] = i;
sz[i] = 1;
}
}
int get_par(int u)
{
if (par[u] == u)
return u;
return par[u] = get_par(par[u]);
}
void merge(int u, int v)
{
u = get_par(u);
v = get_par(v);
if (u == v)
return;
if (sz[u] < sz[v])
swap(u, v);
par[v] = u;
sz[u] += sz[v];
mn[u] = min(mn[u], mn[v]);
}
int dp[N], lst[N];
void init()
{
init_dsu();
vector<pair<int, int>> v;
v.push_back(MP(-1, 0));
for (int i = 1; i <= n; i++)
v.push_back(MP(a[i], i));
sort(all(v));
for (int i = 1; i <= n; i++)
if (v[i].first == v[i - 1].first)
a[v[i].second] = a[v[i - 1].second];
else
a[v[i].second] = 1 + a[v[i - 1].second];
set<int> s;
s.insert(0);
s.insert(n + 1);
for (int i = 1; i <= n; i++)
{
int j = v[i].second;
auto it = s.lower_bound(j);
int r = *it;
it--;
int l = *it;
if (j - l <= d)
merge(j, l);
if (r - j <= d)
merge(j, r);
lst[j] = mn[get_par(j)];
s.insert(j);
}
}
int stress_solve()
{
int best = 0;
for (int mask = 0; mask < (1 << n); mask++)
{
vector<int> v;
for (int i = 0; i < n; i++)
{
if(((1 << i) & mask) == 0)
continue;
v.push_back(i + 1);
}
int mx = -mod;
int res = 0;
for (int i = 0; i < v.size(); i++)
{
if (a[v[i]] > mx)
{
mx = a[v[i]];
res++;
}
if (i && v[i] - v[i - 1] > d)
{
res = 0;
break;
}
}
if (res == 6)
res = res * 1;
best = max(best, res);
}
return best;
}
void solve()
{
cin >> n >> d;
for (int i = 1; i <= n; i++)
cin >> a[i];
init();
for (int i = 1; i <= n; i++)
{
dp[i] = 1;
for (int j = i - 1; j >= lst[i]; j--)
if (a[i] > a[j])
dp[i] = max(dp[i], dp[j] + 1);
}
int ans = 1;
for(int i = 1; i <= n; i++)
ans = max(ans, dp[i]);
cout << ans << endl;
// cout << stress_solve() << endl;
}
int main()
{
fastIO;
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
/*
11 1
1 4 4 5 3 2 1 7 9 8 10
*/
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int stress_solve()':
Main.cpp:125:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
125 | for (int i = 0; i < v.size(); i++)
| ~~^~~~~~~~~~
# | 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... |