Submission #51207

# Submission time Handle Problem Language Result Execution time Memory
51207 2018-06-17T08:40:23 Z zetapi New Home (APIO18_new_home) C++14
0 / 100
5000 ms 800364 KB
#include <bits/stdc++.h>
using namespace std;
 
#define pb  push_back
#define mp  make_pair
#define int long long
#define itr ::iterator 
 
typedef pair<int,int>  pii;
 
const int MAX=5e5;
const int INF=1e8;
 
vector<int> vec[MAX];
vector<pii> increasing,decreasing;
 
int N,K,Q,X,Y,Z,l,r,pre,res[INF+9];
 
bool cmp(pii X,pii Y)
{
	return X.first>Y.first;
}
 
signed main()
{
	ios_base::sync_with_stdio(false);
	/*cin.tie(0);
	cout.tie(0);*/
 
	for(int A=1;A<=INF;A++)
		res[A]=-1;
	cin>>N>>K>>Q;
	for(int A=1;A<=N;A++)
	{
		cin>>X>>Y>>Z>>Z;
		vec[Y].pb(X);
	}
	for(int A=1;A<=K;A++)
	{
		if(vec[A].empty())
			continue;
		sort(vec[A].begin(),vec[A].end());
		for(int B=1;B<vec[A].size();B++)
			increasing.pb(mp(vec[A][B-1],(vec[A][B-1]+vec[A][B])/2));
		for(int B=vec[A].size()-2;B>=0;B--)
			decreasing.pb(mp(vec[A][B+1],(vec[A][B+1]+vec[A][B]+1)/2));		
		for(int B=vec[A][0],C=0;B>=0;B--,C++)
			res[B]=max(res[B],C);
		for(int B=vec[A].back(),C=0;B<=INF;B++,C++)
			res[B]=max(res[B],C);
	}
	sort(increasing.begin(),increasing.end());
	sort(decreasing.begin(),decreasing.end(),cmp);
	/*for(auto A:increasing)
		cout<<A.first<<" inc "<<A.second<<"\n";
	for(auto A:decreasing)
		cout<<A.first<<" dec "<<A.second<<"\n";*/
	for(int A=0;A<increasing.size();A++)
	{
		l=max(pre+1,increasing[A].first);
		r=increasing[A].second;
		for(int B=l,C=l-increasing[A].first;B<=r;B++,C++)
			res[B]=max(res[B],C);
		pre=r;
	}
	pre=INF+99;
	for(int A=decreasing.size()-1;A>=0;A--)
	{
		l=min(pre-1,decreasing[A].first);
		r=decreasing[A].second;
		for(int B=l,C=decreasing[A].first-l;B>=r;B--,C++)
			res[B]=max(res[B],C);
		pre=r;
	}
	while(Q--)
	{
		cin>>X>>Y;
		cout<<res[Y]<<"\n";
	}
	return 0;
}

Compilation message

new_home.cpp: In function 'int main()':
new_home.cpp:43:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int B=1;B<vec[A].size();B++)
               ~^~~~~~~~~~~~~~
new_home.cpp:58:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int A=0;A<increasing.size();A++)
              ~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2192 ms 795000 KB Output is correct
2 Incorrect 2118 ms 795008 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2192 ms 795000 KB Output is correct
2 Incorrect 2118 ms 795008 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5100 ms 799524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5072 ms 800364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2192 ms 795000 KB Output is correct
2 Incorrect 2118 ms 795008 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2192 ms 795000 KB Output is correct
2 Incorrect 2118 ms 795008 KB Output isn't correct
3 Halted 0 ms 0 KB -