This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/extc++.h>
using namespace std;
namespace pbds = __gnu_pbds;
int main() {
int n;
cin >> n;
vector<pair<int,int>> arr(n);
for (auto& [p, x] : arr) cin >> p >> x, p--;
pbds::tree<int, pbds::null_type, less<int>, pbds::rb_tree_tag, pbds::tree_order_statistics_node_update>
st;
for (int i = 0; i < n;i++)
st.insert(i);
reverse(arr.begin(), arr.end());
for (auto &[p, x] : arr) {
auto it = st.find_by_order(p);
p = *it+1;
st.erase(it);
}
reverse(arr.begin(), arr.end());
#ifdef ONPC
for (auto &[p, x] : arr) {
cout << p << ' ' << x << endl;
}
cout <<"---" << endl;
#endif
vector<int> pot(n+1);
for (auto [p, x] : arr) {
pot[p] = x;
vector<int> dp(pot.size());
for (int i = 0; i < (int)pot.size(); i++) {
for (int j = 0; j < i ;j++) {
if (pot[j] < pot[i])
dp[i] = max(dp[i], dp[j]);
}
dp[i]++;
}
cout << *max_element(dp.begin(), dp.end())-1 << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |