QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1064#672184#21687. 【NOIP Round #2】排序zlaxiangqizhenFailed.2024-10-24 16:01:302024-10-24 16:01:30

Details

Extra Test:

Invalid Input

input:

1 1

output:


result:

FAIL Expected EOLN (stdin, line 1)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#672184#21687. 【NOIP Round #2】排序xiangqizhen100 ✓675ms213452kbC++141.8kb2024-10-24 15:58:022024-10-24 15:58:04

answer

#include<bits/stdc++.h>
#define int long long
#define f(i,j,n) for(long long i=j;i<=n;i++)
#define updmax(a,b) a=max(a,b)
#define updmin(a,b) a=min(a,b)
#define pb push_back
#define XQZ
using namespace std;
const int N=5e5+10;
int n,a[N],dp[N],vis[N];
set<pair<int,int> > s1;
set<pair<int,int> > s2;
struct Bit{
	multiset<int> t[N];
	int lowbit(int k){return k&-k;}
	void add(int x,int y){
		for(int i=x+1;i<=n+1;i+=lowbit(i)){
			t[i].insert(y);
		}
	}
	void erase(int x,int y){
		for(int i=x+1;i<=n+1;i+=lowbit(i)){
			multiset<int>::iterator it=t[i].lower_bound(y);
			t[i].erase(it);
		}
	}
	int ask(int x){
		int sum=-1;
		for(int i=x+1;i>=1;i-=lowbit(i)){
			if(t[i].empty())continue;
			updmax(sum,*t[i].rbegin());
		}
		return sum;
	}
}_bit;
void gs(){
	cin>>n;
	f(i,1,n)cin>>a[i];
	int ans=0;
	_bit.add(0,0);
	s1.insert({0,0});
	f(i,1,n){
//		cout<<"==========="<<i<<"=========\n";
		for(set<pair<int,int> >::iterator it=s2.begin();it!=s2.end();){
			set<pair<int,int> >::iterator nx=it;nx++;
			if((*it).first<a[i]){
				if(dp[(*it).second]||(*it).second==0)_bit.erase(a[(*it).second],dp[(*it).second]);
//				cout<<"::"<<(*it).second<<endl;
				vis[(*it).second]=1;
				s2.erase(it);
			}else break;
			it=nx;
		}
		for(set<pair<int,int> >::iterator it=s1.begin();it!=s1.end();){
			set<pair<int,int> >::iterator nx=it;nx++;
			if((*it).first<a[i]){
				s2.insert({a[i],(*it).second});
				s1.erase(it);
			}else break;
			it=nx;
		}
		s1.insert({a[i],i});
		dp[i]=_bit.ask(a[i])+1;
		if(dp[i])_bit.add(a[i],dp[i]);updmax(ans,dp[i]);
//		cout<<dp[i]<<endl;
	}
	cout<<ans<<endl;
}
signed main(){
#ifndef XQZ
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
#ifdef NXD
	int t=0;cin>>t;while(t--)
#endif
		gs();
	return 0;
}