This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Code by Parsa Eslami
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define pb push_back
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lc 2*id
#define rc 2*id+1
#define dmid int mid=(r+l)/2
#define err(x) cout<<#x<<" = "<<x<<'\n'
#define bit(i,j) ((i>>j)&1)
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=2e3+4;
const int NN=2e3+4;
int arr[NN],x[NN],p[NN];
struct fenwick{
int fen[NN];
void upd(int k,int w){
while(k<NN){
maxm(fen[k],w);
k+=(k&(-k));
}
}
int get(int k){
int rt=0;
while(k>0){
maxm(rt,fen[k]);
k-=(k&(-k));
}
return rt;
}
};
fenwick fen;
int32_t main(){
iostream::sync_with_stdio(0); cin.tie(0);
int n; cin>>n;
FOR(i,1,n) cin>>p[i]>>x[i];
ordered_set<int> st0;
FOR(i,1,n) st0.insert(i);
FORR(i,n,1){
p[i]=*st0.find_by_order(p[i]-1);
st0.erase(p[i]);
arr[p[i]]=x[i];
}
vector<pii> comp;
FOR(i,1,n) comp.pb({arr[i],i});
int z=0;
sort(all(comp));
FOR(i,0,SZ(comp)-1){
if(i==0||comp[i].F!=comp[i-1].F) z++;
arr[comp[i].S]=z;
}
bool ok[n+1]={};
FOR(i,1,n){
ok[p[i]]=1;
int ans=0;
FOR(j,1,n) if(ok[j]){
int s=fen.get(arr[j]-1)+1;
fen.upd(arr[j],s);
maxm(ans,s);
}
FOR(j,1,NN-1) fen.fen[j]=0;
cout<<ans<<'\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |