Submission #831121

# Submission time Handle Problem Language Result Execution time Memory
831121 2023-08-19T19:04:07 Z pera Exam (eJOI20_exam) C++17
25 / 100
63 ms 22364 KB
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
const int N = 2e5 + 1;

vector<int> t(4 * N) , x(4 * N) , a(N) , b(N);
map<int , int> M;

void bld(int v , int l , int r){
	if(l == r){
		x[v] = b[l];
		return; 
	}
	int m = (l + r) / 2;
	bld(v * 2 , l , m);
	bld(v * 2 + 1 , m + 1 , r);
	x[v] = max(x[v * 2] , x[v * 2 + 1]);
}

int G(int v , int l , int r , int L , int R){
	if(l > r || r < L || l > R) return 0;
	if(L <= l && r <= R) return x[v];
	int m = (l + r) / 2;
	return max(G(v * 2 , l , m , L , R) , G(v * 2 + 1 , m + 1 , r , L , R));
}

void up(int v , int l ,int r , int p , int x){
	if(l == r){
		t[v] = x;
		return;
	}
	int m = (l + r) / 2;
	if(p <= m) up(v * 2 , l , m , p , x);
	else up(v * 2 + 1 , m + 1 , r , p , x);
	t[v] = max(t[v * 2] , t[v * 2 + 1]);
}

int g(int v , int l , int r , int L , int R){
	if(l > r || r < L || l > R) return 0;
	if(L <= l && r <= R) return t[v];
	int m = (l + r) / 2;
	return max(g(v * 2 , l , m , L , R) , g(v * 2 + 1 , m + 1 , r , L , R));
}
 
main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int n , oK = 1;cin >> n;
	for(int i = 1;i <= n;i ++){
		cin >> a[i];
		M[a[i]] = i;
	}
	for(int i = 1;i <= n;i ++){
		cin >> b[i];
		if(i != 1) oK &= (b[i] == b[i - 1]);
	}
	bld(1 , 1 , n);
	if(oK){
		int c = 0;
		for(int i = 1;i <= n;i ++){
			int cc = 0 , k = 0;
			while(a[i] <= b[i] && i <= n){
				if(a[i] == b[i]) k = 1;
				++ cc , ++ i; 
			}
			if(k) c += cc;
		}
		cout << c << endl;
	}else{
		oK = 1;
		for(int i = 2;i <= n;i ++){
			oK &= (a[i] > a[i - 1]);
		}
		if(oK){
			vector<int> dp(n + 1);
			dp[1] = (a[1] == b[1]);
			for(int i = 2;i <= n;i ++){
				int q = 0;
				for(int j = i;j >= 1;j --){
					q += (a[i] == b[j]);
					dp[i] = max(dp[i] , q + dp[j - 1]);
				}
				for(int j = 1;j <= i;j ++){
					dp[j] = max(dp[j] , dp[j - 1] + (a[i] == b[j]));
				}
			}
			cout << *max_element(dp.begin() , dp.end()) << endl;
		}else if(M.size() == n){
			vector<int> ans(n + 1);
			for(int i = 1;i <= n;i ++){
				if(M.find(b[i]) != M.end()){
					int p = M[b[i]];
					//cout << G(1 , 1 , n , min(i , p) , max(i , p)) << endl;
					if(G(1 , 1 , n , min(i , p) , max(i , p)) != b[i]) continue;
					ans[i] = g(1 , 1 , n , 1 , p) + 1;
					up(1 , 1 , n , p , ans[i]);
				}
			}
			cout << *max_element(ans.begin() , ans.end()) << endl;
		}
	}
}

Compilation message

exam.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   47 | main(){
      | ^~~~
exam.cpp: In function 'int main()':
exam.cpp:90:21: warning: comparison of integer expressions of different signedness: 'std::map<long long int, long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   90 |   }else if(M.size() == n){
      |            ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15956 KB Output is correct
2 Incorrect 6 ms 15956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15956 KB Output is correct
2 Correct 10 ms 16004 KB Output is correct
3 Correct 30 ms 21740 KB Output is correct
4 Correct 14 ms 16120 KB Output is correct
5 Correct 48 ms 22364 KB Output is correct
6 Correct 14 ms 16084 KB Output is correct
7 Correct 16 ms 16084 KB Output is correct
8 Correct 42 ms 20000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15956 KB Output is correct
2 Correct 7 ms 15976 KB Output is correct
3 Correct 17 ms 16252 KB Output is correct
4 Correct 58 ms 16356 KB Output is correct
5 Correct 63 ms 16384 KB Output is correct
6 Correct 63 ms 16388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 16340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15956 KB Output is correct
2 Incorrect 6 ms 15956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15956 KB Output is correct
2 Incorrect 6 ms 15956 KB Output isn't correct
3 Halted 0 ms 0 KB -