이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
* Author: Nonoze
* Created: Saturday 27/07/2024
*/
#include <bits/stdc++.h>
using namespace std;
#ifndef _IN_LOCAL
#define dbg(...)
#endif
#define endl '\n'
#define endlfl '\n' << flush
#define quit(x) return (void)(cout << x << endl)
template<typename T> void read(T& x, bool write=0, bool write2=1) { if (write && write2) cout << x << endl; else if (write) cout << x << ' '; else cin >> x;}
template<typename T1, typename T2> void read(pair<T1, T2>& p, bool write=0, bool write2=1) { read(p.first, write, 0), read(p.second, write, 0); if (write && write2) cout << endl;}
template<typename T> void read(vector<T>& v, bool write=0) { for (auto& x : v) read(x, write, 0); if (write) cout << endl; }
template<typename T1, typename T2> void read(T1& x, T2& y, bool write=0) { read(x, write), read(y, write); if (write) cout << endl; }
template<typename T1, typename T2, typename T3> void read(T1& x, T2& y, T3& z, bool write=0) { read(x, write), read(y, write), read(z, write); if (write) cout << endl; }
template<typename T1, typename T2, typename T3, typename T4> void read(T1& x, T2& y, T3& z, T4& zz, bool write=0) { read(x, write), read(y, write), read(z, write), read(zz, write); if (write) cout << endl; }
template<typename T> void print(T x) { read(x, 1); }
template<typename T1, typename T2> void print(T1 x, T2 y) { read(x, y, 1); }
template<typename T1, typename T2, typename T3> void print(T1 x, T2 y, T3 z) { read(x, y, z, 1); }
template<typename T1, typename T2, typename T3, typename T4> void print(T1 x, T2 y, T3 z, T4 zz) { read(x, y, z, zz, 1); }
#define sz(x) (int)(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define cmin(a, b) a = min(a, b)
#define cmax(a, b) a = max(a, b)
#define int long long
const int inf = numeric_limits<int>::max() / 4;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9+7, LOG=25;
void solve();
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;
// cin >> tt;
while(tt--) solve();
return 0;
}
struct SegTree {
int n;
vector<int> t;
SegTree(int _n) {
n=_n;
t.resize(4*n);
}
void update(int x, int val, int node=1, int l=0, int r=-1) { if (r==-1) r=n-1;
if (l>x || r<x) return;
if (l==r) {
t[node]=val;
return;
}
int mid=(l+r)/2;
update(x, val, node*2, l, mid);
update(x, val, node*2+1, mid+1, r);
t[node]=max(t[node*2], t[node*2+1]);
}
int query(int x, int node=1, int l=0, int r=-1) { if (r==-1) r=n-1;
if (l>x) return 0;
if (r<=x) return t[node];
int mid=(l+r)/2;
int s1=query(x, node*2, l, mid);
int s2=query(x, node*2+1, mid+1, r);
return max(s1, s2);
}
};
int n, k, m, q;
vector<pair<int, int>> a;
void solve() {
read(n);
a.clear(), a.resize(n); read(a);
for (int i=0; i<n; i++) a[i].fi=i-a[i].fi-1, a[i].se+=i+1;
SegTree st(n);
vector<vector<int>> toadd(2*n+1);
vector<int> ans(n);
for (int i=0; i<n; i++) {
toadd[a[i].se].pb(i);
for (auto u: toadd[i]) st.update(u, ans[u]);
ans[i]=st.query(a[i].fi)+1;
}
cout << *max_element(all(ans)) << endl;
}
# | 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... |