답안 #468914

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
468914 2021-08-30T07:43:05 Z MohammadParsaElahimanesh LIS (INOI20_lis) C++14
20 / 100
4000 ms 47892 KB
/// IN THE NAME OF GOD

#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("Ofast","O3","unroll-loops")
//#pragma GGC target("avx2","fma")
//#pragma GCC optimize("no-stack-protector")

#define upp upper_bound
#define low lower_bound
#define pub push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define FOR(i,a) for(int i = 0; i < a; i++)
#define RFOR(i,a) for(int i = a-1; i >= 0; i--)
#define Fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define maxer(a,b) if(a < b)a=b;
#define fi first
#define se second


typedef double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;

const int N = 1'000'000 + 5;
pii Q[N];
int q;
set<int> X[N];
int nx[N], pr[N];
int ans = 0;

inline int LIS(vector<int> const& a)
{
	vector<int> LO;
	int pos, np = sz(a);
	FOR(i,np)
	{
		pos = low(all(LO), a[i]) - LO.begin();
		if(pos == sz(LO)){LO.pub(a[i]);}
		else LO[pos] = a[i];
	}
	return sz(LO);
}


int main()
{
	Fast
	
	vector<int> T;
	cin >> q;
	
	FOR(i,q)
	{
		cin >> Q[i].fi >> Q[i].se;
		T.insert(T.begin()+Q[i].fi-1,Q[i].se);
		cout << LIS(T) << '\n';
	}
	
	
	
	
	return 0;
	//vector<int> T;
	FOR(i,q)
	{
		T.insert(T.begin()+Q[i].fi-1,i);
	}
	FOR(i,sz(T))Q[T[i]].fi = i;
	
	set<int> num;
	
	FOR(i,q)nx[Q[i].fi] = pr[Q[i].fi] = 1;
	
	FOR(i,q)
	{
		for(auto u: num)
		{
			if(u < Q[i].se)
			{
				auto l = X[u].low(Q[i].fi);
				if(l != X[u].begin())
				{
					--l;
					//cout << "## " << *(l) << '\n';
					maxer(pr[Q[i].fi],1+pr[*(l)]);
				}
			}
			else if(u > Q[i].se)
			{
				auto l = X[u].low(Q[i].fi);
				if(l != X[u].end())
				{
					//cout << "# " << *l << '\n';
					maxer(nx[Q[i].fi],1+nx[*l]);
				}
			}
		}
		for(auto u: num)
		{
			if(u < Q[i].se)
			{
				auto l = X[u].low(Q[i].fi);
				if(l != X[u].begin())
				{
					--l;
					maxer(nx[*l],1+nx[Q[i].fi]);
					maxer(ans,pr[*(l)]+nx[*l]-1);
				}
			}
			else if(u > Q[i].se)
			{
				auto l = X[u].low(Q[i].fi);
				if(l != X[u].end())
				{
					//cout << " I'm bad : " << *l << '\n';
					maxer(pr[*l],1+pr[Q[i].fi]);
					maxer(ans,pr[*l]+nx[*l]-1);
				}
			}
		}
		maxer(ans,nx[Q[i].fi]+pr[Q[i].fi]-1);
		X[Q[i].se].insert(Q[i].fi);
		num.insert(Q[i].se);
		cout << ans << '\n';
		/*FOR(i,q)
		{
			cout << pr[Q[i].fi] << ", " << nx[Q[i].fi] << " va ";
		}
		cout << '\n';*/
	}
	
	return 0;
}

/// thank god
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 47248 KB Output is correct
2 Correct 29 ms 47228 KB Output is correct
3 Correct 54 ms 47324 KB Output is correct
4 Correct 67 ms 47308 KB Output is correct
5 Correct 53 ms 47312 KB Output is correct
6 Correct 70 ms 47284 KB Output is correct
7 Correct 53 ms 47312 KB Output is correct
8 Correct 51 ms 47316 KB Output is correct
9 Correct 54 ms 47288 KB Output is correct
10 Correct 54 ms 47300 KB Output is correct
11 Correct 62 ms 47220 KB Output is correct
12 Correct 69 ms 47264 KB Output is correct
13 Correct 76 ms 47308 KB Output is correct
14 Correct 72 ms 47308 KB Output is correct
15 Correct 69 ms 47312 KB Output is correct
16 Correct 73 ms 47312 KB Output is correct
17 Correct 74 ms 47440 KB Output is correct
18 Correct 72 ms 47304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 47248 KB Output is correct
2 Correct 29 ms 47228 KB Output is correct
3 Correct 54 ms 47324 KB Output is correct
4 Correct 67 ms 47308 KB Output is correct
5 Correct 53 ms 47312 KB Output is correct
6 Correct 70 ms 47284 KB Output is correct
7 Correct 53 ms 47312 KB Output is correct
8 Correct 51 ms 47316 KB Output is correct
9 Correct 54 ms 47288 KB Output is correct
10 Correct 54 ms 47300 KB Output is correct
11 Correct 62 ms 47220 KB Output is correct
12 Correct 69 ms 47264 KB Output is correct
13 Correct 76 ms 47308 KB Output is correct
14 Correct 72 ms 47308 KB Output is correct
15 Correct 69 ms 47312 KB Output is correct
16 Correct 73 ms 47312 KB Output is correct
17 Correct 74 ms 47440 KB Output is correct
18 Correct 72 ms 47304 KB Output is correct
19 Execution timed out 4056 ms 47892 KB Time limit exceeded
20 Halted 0 ms 0 KB -