이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pb push_back
#define US freopen("revegetate.in", "r", stdin); freopen("revegetate.out", "w", stdout);
#define m_p make_pair
#define moo -1000000000000000;
#define poo 1000000000000000;
ll gcd(ll a, ll b)
{
if (a == 0 || b == 0) {
return max(a, b);
}
if (a <= b) {
return gcd(a, b % a);
}
else {
return gcd(a % b, b);
}
}
ll lcm(ll a, ll b) {
return (a / gcd(a, b)) * b;
}
const int N = 300010;
ll mx[N];
ll a[N];
ll b[N];
ll ans[N];
void solve() {
int n, d;
cin >> n >> d;
for (int i = 1;i <= n;i++) {
cin >> a[i];
}
if (d == 1) {
if (n == 1) {
cout << 1 << endl;
return;
}
ll pat = 1, l = n - 1, r = n;
mx[n] = a[n];
ans[n] = 1;
for (int i = n - 1;i >= 1;i--) {
ll kk = n + 1;
r = n;
// cout << i << " " << l << " " << r << endl;
while (l <= r) {
ll mid = (l + r) / 2;
//cout << i << " " << mid << " " << mx[mid] << endl;
if (mx[mid] > a[i]) {
kk = mid;
r = mid-1;
}
else {
l = mid+1;
}
}
//cout << kk << " " << i << endl;
if (kk != n + 1) {
pat = max(ans[kk]+1, pat);
ans[kk - 1] = ans[kk] + 1;
mx[kk-1] = a[i];
l = kk-1;
}
else {
l = n;
ans[l] = 1;
mx[l] = a[i];
}
}
cout << pat << endl;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//US
int tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
}
# | 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... |