Submission #315657

#TimeUsernameProblemLanguageResultExecution timeMemory
315657tengiz05Jousting tournament (IOI12_tournament)C++17
0 / 100
1099 ms8440 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;
//order_of_key(x) = position of element x;
//find_by_order(i) = a[i];
const int N = 1e5+5;
int dp[N], k[N], par[N], n, m;
bool used[N];
vector<int> edges[N];
int mxans=0, indans=0;
vector<pair<int, int>> temp;
bool cmp(pair<int, int> &f, pair<int, int> &s){
	if(f.second > s.second)return true;
	else if(f.second < s.second)return false;
	else {
		if(f.first < s.first)return true;
		else return false;
	}
}
void dfs(int u){
//	cout << u << ' ';
	used[u] = true;
	int ans = 0;
	for(auto v : edges[u]){
		if(used[v])continue;
		dfs(v);
		ans = max(ans, dp[v]);
	}
	int l = temp[u].first, r = temp[u].second;
	if(k[l] == k[r-1])dp[u] = ans+1;
	else dp[u] = ans;
	if(dp[u] > mxans){
		mxans = dp[u];
		indans = u;
	}//cout << l << ' ' << r << '\n';
}
int GetBestPosition(int NN, int C, int R, int *K, int *S, int *E) {
	n = NN, m = C;
	ordered_set<int> s1, s2;
	for(int i=0;i<n;i++)s1.insert(i), s2.insert(i);
	for(int i=0;i<n;i++){
		if(K[i] > R)k[i] = 1;
		else k[i] = 0;
		if(i)k[i] += k[i-1];
	}
	for(int i=0;i<m;i++){
		int l = *s1.find_by_order(S[i]);
		int r = *s2.find_by_order(E[i]);
		for(int j=S[i];S[i]+1<s1.size()&&*s1.find_by_order(S[i]+1)<= E[i];j++)s1.erase(s1.find_by_order(S[i]+1));
		for(int j=S[i];S[i]+0<s2.size()&&*s2.find_by_order(S[i]+0) < E[i];j++)s2.erase(s2.find_by_order(S[i]+0));
		
		temp.push_back({l, r});
	}
	sort(temp.begin(), temp.end(), cmp);
/*	for(auto X : temp){
		cout << X.first << ' ' << X.second << '\n';
	}*/
	int u = 0;
	int l=temp[0].first, r=temp[0].second,i=1;
	while(i < temp.size()){
		auto x = temp[i];
		if(x.first > r || x.second < l){
			u = par[u];
			continue;
		}
		edges[u].push_back(i);
		edges[i].push_back(u);
		par[i] = u;u=i;
		i++;
	}
	dfs(0);
	return indans;
}
/*

5 3 3
1
0
2
4
1 3
0 1
0 1

*/

Compilation message (stderr)

tournament.cpp: In function 'int GetBestPosition(int, int, int, int*, int*, int*)':
tournament.cpp:52:24: warning: comparison of integer expressions of different signedness: 'int' and '__gnu_pbds::detail::bin_search_tree_set<int, __gnu_pbds::null_type, std::less<int>, __gnu_pbds::detail::tree_traits<int, __gnu_pbds::null_type, std::less<int>, __gnu_pbds::tree_order_statistics_node_update, __gnu_pbds::rb_tree_tag, std::allocator<char> >, std::allocator<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for(int j=S[i];S[i]+1<s1.size()&&*s1.find_by_order(S[i]+1)<= E[i];j++)s1.erase(s1.find_by_order(S[i]+1));
      |                  ~~~~~~^~~~~~~~~~
tournament.cpp:53:24: warning: comparison of integer expressions of different signedness: 'int' and '__gnu_pbds::detail::bin_search_tree_set<int, __gnu_pbds::null_type, std::less<int>, __gnu_pbds::detail::tree_traits<int, __gnu_pbds::null_type, std::less<int>, __gnu_pbds::tree_order_statistics_node_update, __gnu_pbds::rb_tree_tag, std::allocator<char> >, std::allocator<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int j=S[i];S[i]+0<s2.size()&&*s2.find_by_order(S[i]+0) < E[i];j++)s2.erase(s2.find_by_order(S[i]+0));
      |                  ~~~~~~^~~~~~~~~~
tournament.cpp:63:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  while(i < temp.size()){
      |        ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...