Submission #463554

# Submission time Handle Problem Language Result Execution time Memory
463554 2021-08-11T10:07:40 Z Kerim Exam (eJOI20_exam) C++17
88 / 100
1000 ms 14948 KB
#include "bits/stdc++.h"
#define MAXN 200009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;
 
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int a[MAXN],b[MAXN],n,c,ans;
map<int,int>pm;
vector<int>adj[MAXN];
int F[MAXN],l[MAXN],r[MAXN];
void upd(int x,int val){
	for(;x<MAXN;x+=x&(-x))
		umax(F[x],val);
}
int tap(int x){
	int res=0;
	for(;x;x-=x&(-x))
		umax(res,F[x]);
	return res;
}
int main(){
    //~ freopen("file.in", "r", stdin);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)	
		scanf("%d",a+i),pm[a[i]]=1;
	for(int i=1;i<=n;i++)
		scanf("%d",b+i),pm[b[i]]=1;
	a[0]=a[n+1]=INF;
	tr(it,pm)it->ss=++c;
	stack<int>st;
	st.push(0);
	for(int i=1;i<=n;i++){
		while(!st.empty() and a[st.top()]<a[i])st.pop();
		l[i]=st.top();
		st.push(i);
	}
	while(!st.empty())st.pop();
	st.push(n+1);
	for(int i=n;i>=1;i--){
		while(!st.empty() and a[st.top()]<a[i])st.pop();
		r[i]=st.top();
		st.push(i);
	}
	for(int i=1;i<=n;i++)adj[pm[a[i]]].pb(i);
	for(int i=1;i<=n;i++){
		vector<int>&v=adj[pm[b[i]]];
		if(v.empty())continue;
		for(int ind=v.size()-1;ind>=0;ind--){
			int j=v[ind];
			if(i<=l[j] or r[j]<=i)continue;
			int dp=tap(j)+1;
			umax(ans,dp);
			upd(j,dp);
		}
	}
	printf("%d\n",ans);
	return 0;
}

Compilation message

exam.cpp: In function 'int main()':
exam.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
exam.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d",a+i),pm[a[i]]=1;
      |   ~~~~~^~~~~~~~~~
exam.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d",b+i),pm[b[i]]=1;
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 5 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 63 ms 5520 KB Output is correct
3 Correct 70 ms 13372 KB Output is correct
4 Correct 32 ms 7424 KB Output is correct
5 Correct 129 ms 14372 KB Output is correct
6 Execution timed out 1092 ms 7360 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 5024 KB Output is correct
3 Correct 5 ms 5204 KB Output is correct
4 Correct 7 ms 5452 KB Output is correct
5 Correct 7 ms 5452 KB Output is correct
6 Correct 8 ms 5532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5452 KB Output is correct
2 Correct 57 ms 8784 KB Output is correct
3 Correct 194 ms 14504 KB Output is correct
4 Correct 210 ms 14616 KB Output is correct
5 Correct 138 ms 14736 KB Output is correct
6 Correct 173 ms 14764 KB Output is correct
7 Correct 133 ms 14948 KB Output is correct
8 Correct 222 ms 14672 KB Output is correct
9 Correct 219 ms 14788 KB Output is correct
10 Correct 108 ms 14696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 5 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4964 KB Output is correct
8 Correct 3 ms 4940 KB Output is correct
9 Correct 4 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 3 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 5068 KB Output is correct
14 Correct 3 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 5 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 3 ms 5024 KB Output is correct
9 Correct 5 ms 5204 KB Output is correct
10 Correct 7 ms 5452 KB Output is correct
11 Correct 7 ms 5452 KB Output is correct
12 Correct 8 ms 5532 KB Output is correct
13 Correct 3 ms 4964 KB Output is correct
14 Correct 3 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 3 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 3 ms 4940 KB Output is correct
19 Correct 3 ms 5068 KB Output is correct
20 Correct 3 ms 5068 KB Output is correct
21 Correct 3 ms 4940 KB Output is correct
22 Correct 4 ms 5052 KB Output is correct
23 Correct 32 ms 5196 KB Output is correct
24 Correct 17 ms 5068 KB Output is correct
25 Correct 8 ms 5068 KB Output is correct
26 Correct 6 ms 5196 KB Output is correct
27 Correct 7 ms 5068 KB Output is correct
28 Correct 9 ms 5376 KB Output is correct
29 Correct 9 ms 5356 KB Output is correct
30 Correct 8 ms 5364 KB Output is correct
31 Correct 9 ms 5444 KB Output is correct
32 Correct 8 ms 5436 KB Output is correct