//Bismillahi Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pll> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;
double EPS = 1e-9;
const int N = 1e5;
const ll inf =1000001;
double PI = acos(-1);
const int MX = 2e5 + 5;
const int MS = 30;
int dirx[4] = { 1,0,-1,0 };
int diry[4] = { 0,1,0,-1 };
ll sx,sy,fx,x,fy,Z,m,n,k,y,ans,f[1000001],b[inf],a[inf],r,res,cur,ans1,flag,flag1,flag2,flag3,flag4,cnt,cnt1,cnt2,cnt3,minn,maxx,maxx1,sum,sum1,ans2,ans3;
vector<ll> adj[200000];
vi z,z1;
char c[505][505];
ll visited[500001],color[500001];
vector<ll> dist;
ll mat[1001][1001];
string str,str1,str2,str3;
const int md = 1e9+7;
vector<vector<pair<int,int>>> g;
vector<pair<ll,ll>>v;
vl v2;
priority_queue<pair<pair<long long, int>, bool> > pq;
map<ll,ll>mp;
map<char,ll>mp1;
queue<ll> q;
set<ll>s;
multiset<LL> ms;
stack<LL>st;
double pi=3.14159265358979323846;
bool ok[505][505];
vector<ll> v1[500001];
bool prime[200001];
vector<char> path;
ll is[N+1];
ll dp[505][505];
ll en[200001],ex[200001],tour[200001],depth[200001],segtree[inf];
ll up[MS][MX];
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b)-1; (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a,b) a=max(a,b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define TC(t) while (t--)
#define ins insert
#define PERMUTE next_permutation
/*********/
ll find_lis(vector<ll> a) {
vector<ll> dp;
for (ll i : a) {
ll pos = lower_bound(dp.begin(), dp.end(), i) - dp.begin();
if (pos == dp.size()) {
dp.push_back(i);
} else {
dp[pos] = i;
}
}
return dp.size();
}
void solve()
{
cin >> n >> x;
FOR(i,0,n)
{
cin >> y;
z.pb(y);
}
vector<ll> v(n,INT_MAX);
FOR(i,0,n)
{
ll pos = lower_bound(v.begin(), v.end(), z[i]) - v.begin();
v[pos]=z[i];
b[i]=pos+1;
maxx=max(maxx,b[i]);
}
v=vector<ll>(n,INT_MAX);
for(int i =n-1;i>=0;i--)
{
ll pos = lower_bound(v.begin(),v.end(),-z[i]+x) - v.begin();
maxx=max(maxx,pos+b[i]);
ll pos1=lower_bound(v.begin(), v.end(), -z[i]) - v.begin();
v[pos1]=-z[i];
}
cout << maxx << endl;
}
/*********/
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
int i =1;
//cin >> t;
//freopen("snakes.in", "r", stdin);
//freopen("snakes.out", "w", stdout);
TC(t)
{
solve();
}
return 0;
}
Compilation message
glo.cpp: In function 'll find_lis(std::vector<long long int>)':
glo.cpp:80:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | if (pos == dp.size()) {
| ~~~~^~~~~~~~~~~~
glo.cpp: In function 'void solve()':
glo.cpp:50:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
50 | #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
| ^
glo.cpp:93:5: note: in expansion of macro 'FOR'
93 | FOR(i,0,n)
| ^~~
glo.cpp:50:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
50 | #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
| ^
glo.cpp:99:5: note: in expansion of macro 'FOR'
99 | FOR(i,0,n)
| ^~~
glo.cpp: In function 'int main()':
glo.cpp:124:9: warning: unused variable 'i' [-Wunused-variable]
124 | int i =1;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16724 KB |
Output is correct |
2 |
Correct |
8 ms |
16704 KB |
Output is correct |
3 |
Correct |
10 ms |
16804 KB |
Output is correct |
4 |
Correct |
9 ms |
16844 KB |
Output is correct |
5 |
Correct |
9 ms |
16724 KB |
Output is correct |
6 |
Correct |
9 ms |
16796 KB |
Output is correct |
7 |
Correct |
11 ms |
16724 KB |
Output is correct |
8 |
Correct |
9 ms |
16724 KB |
Output is correct |
9 |
Correct |
9 ms |
16724 KB |
Output is correct |
10 |
Correct |
10 ms |
16764 KB |
Output is correct |
11 |
Correct |
9 ms |
16724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16724 KB |
Output is correct |
2 |
Correct |
8 ms |
16704 KB |
Output is correct |
3 |
Correct |
10 ms |
16804 KB |
Output is correct |
4 |
Correct |
9 ms |
16844 KB |
Output is correct |
5 |
Correct |
9 ms |
16724 KB |
Output is correct |
6 |
Correct |
9 ms |
16796 KB |
Output is correct |
7 |
Correct |
11 ms |
16724 KB |
Output is correct |
8 |
Correct |
9 ms |
16724 KB |
Output is correct |
9 |
Correct |
9 ms |
16724 KB |
Output is correct |
10 |
Correct |
10 ms |
16764 KB |
Output is correct |
11 |
Correct |
9 ms |
16724 KB |
Output is correct |
12 |
Correct |
9 ms |
16724 KB |
Output is correct |
13 |
Correct |
9 ms |
16724 KB |
Output is correct |
14 |
Correct |
9 ms |
16804 KB |
Output is correct |
15 |
Correct |
10 ms |
16800 KB |
Output is correct |
16 |
Correct |
10 ms |
16784 KB |
Output is correct |
17 |
Correct |
10 ms |
16724 KB |
Output is correct |
18 |
Correct |
10 ms |
16808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16724 KB |
Output is correct |
2 |
Correct |
8 ms |
16704 KB |
Output is correct |
3 |
Correct |
10 ms |
16804 KB |
Output is correct |
4 |
Correct |
9 ms |
16844 KB |
Output is correct |
5 |
Correct |
9 ms |
16724 KB |
Output is correct |
6 |
Correct |
9 ms |
16796 KB |
Output is correct |
7 |
Correct |
11 ms |
16724 KB |
Output is correct |
8 |
Correct |
9 ms |
16724 KB |
Output is correct |
9 |
Correct |
9 ms |
16724 KB |
Output is correct |
10 |
Correct |
10 ms |
16764 KB |
Output is correct |
11 |
Correct |
9 ms |
16724 KB |
Output is correct |
12 |
Correct |
9 ms |
16724 KB |
Output is correct |
13 |
Correct |
9 ms |
16724 KB |
Output is correct |
14 |
Correct |
9 ms |
16804 KB |
Output is correct |
15 |
Correct |
10 ms |
16800 KB |
Output is correct |
16 |
Correct |
10 ms |
16784 KB |
Output is correct |
17 |
Correct |
10 ms |
16724 KB |
Output is correct |
18 |
Correct |
10 ms |
16808 KB |
Output is correct |
19 |
Correct |
10 ms |
16764 KB |
Output is correct |
20 |
Correct |
10 ms |
16768 KB |
Output is correct |
21 |
Correct |
9 ms |
16852 KB |
Output is correct |
22 |
Correct |
9 ms |
16808 KB |
Output is correct |
23 |
Correct |
9 ms |
16852 KB |
Output is correct |
24 |
Correct |
10 ms |
16852 KB |
Output is correct |
25 |
Correct |
9 ms |
16852 KB |
Output is correct |
26 |
Correct |
11 ms |
16724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
23500 KB |
Output is correct |
2 |
Correct |
62 ms |
23492 KB |
Output is correct |
3 |
Correct |
61 ms |
23548 KB |
Output is correct |
4 |
Correct |
62 ms |
23500 KB |
Output is correct |
5 |
Correct |
48 ms |
23584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
18860 KB |
Output is correct |
2 |
Correct |
21 ms |
18888 KB |
Output is correct |
3 |
Correct |
21 ms |
19028 KB |
Output is correct |
4 |
Correct |
22 ms |
18740 KB |
Output is correct |
5 |
Correct |
9 ms |
16804 KB |
Output is correct |
6 |
Correct |
18 ms |
18740 KB |
Output is correct |
7 |
Correct |
20 ms |
18976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
20448 KB |
Output is correct |
2 |
Correct |
32 ms |
20948 KB |
Output is correct |
3 |
Correct |
58 ms |
25056 KB |
Output is correct |
4 |
Correct |
50 ms |
24260 KB |
Output is correct |
5 |
Correct |
31 ms |
20652 KB |
Output is correct |
6 |
Correct |
42 ms |
24040 KB |
Output is correct |
7 |
Correct |
47 ms |
24716 KB |
Output is correct |
8 |
Correct |
28 ms |
21012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16724 KB |
Output is correct |
2 |
Correct |
8 ms |
16704 KB |
Output is correct |
3 |
Correct |
10 ms |
16804 KB |
Output is correct |
4 |
Correct |
9 ms |
16844 KB |
Output is correct |
5 |
Correct |
9 ms |
16724 KB |
Output is correct |
6 |
Correct |
9 ms |
16796 KB |
Output is correct |
7 |
Correct |
11 ms |
16724 KB |
Output is correct |
8 |
Correct |
9 ms |
16724 KB |
Output is correct |
9 |
Correct |
9 ms |
16724 KB |
Output is correct |
10 |
Correct |
10 ms |
16764 KB |
Output is correct |
11 |
Correct |
9 ms |
16724 KB |
Output is correct |
12 |
Correct |
9 ms |
16724 KB |
Output is correct |
13 |
Correct |
9 ms |
16724 KB |
Output is correct |
14 |
Correct |
9 ms |
16804 KB |
Output is correct |
15 |
Correct |
10 ms |
16800 KB |
Output is correct |
16 |
Correct |
10 ms |
16784 KB |
Output is correct |
17 |
Correct |
10 ms |
16724 KB |
Output is correct |
18 |
Correct |
10 ms |
16808 KB |
Output is correct |
19 |
Correct |
10 ms |
16764 KB |
Output is correct |
20 |
Correct |
10 ms |
16768 KB |
Output is correct |
21 |
Correct |
9 ms |
16852 KB |
Output is correct |
22 |
Correct |
9 ms |
16808 KB |
Output is correct |
23 |
Correct |
9 ms |
16852 KB |
Output is correct |
24 |
Correct |
10 ms |
16852 KB |
Output is correct |
25 |
Correct |
9 ms |
16852 KB |
Output is correct |
26 |
Correct |
11 ms |
16724 KB |
Output is correct |
27 |
Correct |
70 ms |
23500 KB |
Output is correct |
28 |
Correct |
62 ms |
23492 KB |
Output is correct |
29 |
Correct |
61 ms |
23548 KB |
Output is correct |
30 |
Correct |
62 ms |
23500 KB |
Output is correct |
31 |
Correct |
48 ms |
23584 KB |
Output is correct |
32 |
Correct |
21 ms |
18860 KB |
Output is correct |
33 |
Correct |
21 ms |
18888 KB |
Output is correct |
34 |
Correct |
21 ms |
19028 KB |
Output is correct |
35 |
Correct |
22 ms |
18740 KB |
Output is correct |
36 |
Correct |
9 ms |
16804 KB |
Output is correct |
37 |
Correct |
18 ms |
18740 KB |
Output is correct |
38 |
Correct |
20 ms |
18976 KB |
Output is correct |
39 |
Correct |
33 ms |
20448 KB |
Output is correct |
40 |
Correct |
32 ms |
20948 KB |
Output is correct |
41 |
Correct |
58 ms |
25056 KB |
Output is correct |
42 |
Correct |
50 ms |
24260 KB |
Output is correct |
43 |
Correct |
31 ms |
20652 KB |
Output is correct |
44 |
Correct |
42 ms |
24040 KB |
Output is correct |
45 |
Correct |
47 ms |
24716 KB |
Output is correct |
46 |
Correct |
28 ms |
21012 KB |
Output is correct |
47 |
Correct |
35 ms |
20936 KB |
Output is correct |
48 |
Correct |
38 ms |
20936 KB |
Output is correct |
49 |
Correct |
65 ms |
25116 KB |
Output is correct |
50 |
Correct |
49 ms |
24372 KB |
Output is correct |
51 |
Correct |
42 ms |
22436 KB |
Output is correct |
52 |
Correct |
49 ms |
24488 KB |
Output is correct |
53 |
Correct |
47 ms |
24396 KB |
Output is correct |
54 |
Correct |
57 ms |
25168 KB |
Output is correct |
55 |
Correct |
54 ms |
25052 KB |
Output is correct |