답안 #51688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51688 2018-06-20T03:02:16 Z zetapi 새 집 (APIO18_new_home) C++14
컴파일 오류
0 ms 0 KB
#include#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> fst_,sec_,vec[MAX];
vector<pii> fst,sec,increasing,decreasing;
 
int N,K,Q,X,Y,Z,l,r,pre,res,Begin,End;
 
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);*/
 
 	Begin=0;
 	End=INF;
	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())
		{
			while(Q--)
				cout<<-1<<"\n";
			return 0;
		}
		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));		
		increasing.pb(mp(vec[A].back(),INF));
		decreasing.pb(mp(*vec[A].begin(),0));
		Begin=max(Begin,*vec[A].begin());
		End=min(End,vec[A].back());
	}
	sort(increasing.begin(),increasing.end());
	sort(decreasing.begin(),decreasing.end());
	for(int A=0;A<increasing.size();A++)
	{
		l=max(pre+1,increasing[A].first);
		r=increasing[A].second;
		if(l>r)
			continue;
		fst.pb(mp(l,r));
		fst_.pb(increasing[A].first);
		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;
		if(l<r)
			continue;
		sec.pb(mp(r,l));
		sec_.pb(decreasing[A].first);
		pre=r;
	}
	reverse(sec.begin(),sec.end());
	reverse(sec_.begin(),sec_.end());
	/*for(auto A:fst)
		cout<<A.first<<" fst "<<A.second<<"\n";
	for(auto A:sec)
		cout<<A.first<<" sec "<<A.second<<"\n";*/
	while(Q--)
	{
		res=0;
		cin>>X>>Y;
		/*if(X<Begin)
		{
			cout<<Begin-X<<"\n";
			continue;
		}
		else if(X>End)
		{
			cout<<X-End<<"\n";
			continue;
		}*/
		int low=0,high=fst.size()-1,mid;
		while(low<=high)
		{
			mid=(low+high)/2;
			if(fst[mid].first<=X and fst[mid].second>=X)
			{
				res=max(res,abs(X-fst_[mid]));
				break;
			}
			else if(fst[mid].second<X)
				low=mid+1;
			else if(fst[mid].first>X)
				high=mid-1;
		}
		low=0,high=sec.size()-1;
		while(low<=high)
		{
			mid=(low+high)/2;
			if(sec[mid].first<=X and sec[mid].second>=X)
			{
				res=max(res,abs(sec_[mid]-X));
				break;
			}
			else if(sec[mid].second<X)
				low=mid+1;
			else if(sec[mid].first>X)
				high=mid-1;
		}
		cout<<res<<"\n";
	}
	return 0;
}

Compilation message

new_home.cpp:2:9: error: #include expects "FILENAME" or <FILENAME>
 #include#include <bits/stdc++.h>
         ^
new_home.cpp:10:9: error: 'pair' does not name a type
 typedef pair<int,int>  pii;
         ^~~~
new_home.cpp:15:1: error: 'vector' does not name a type
 vector<int> fst_,sec_,vec[MAX];
 ^~~~~~
new_home.cpp:16:1: error: 'vector' does not name a type
 vector<pii> fst,sec,increasing,decreasing;
 ^~~~~~
new_home.cpp:20:10: error: 'pii' was not declared in this scope
 bool cmp(pii X,pii Y)
          ^~~
new_home.cpp:20:16: error: 'pii' was not declared in this scope
 bool cmp(pii X,pii Y)
                ^~~
new_home.cpp:20:21: error: expression list treated as compound expression in initializer [-fpermissive]
 bool cmp(pii X,pii Y)
                     ^
new_home.cpp: In function 'int main()':
new_home.cpp:27:2: error: 'ios_base' has not been declared
  ios_base::sync_with_stdio(false);
  ^~~~~~~~
new_home.cpp:33:2: error: 'cin' was not declared in this scope
  cin>>N>>K>>Q;
  ^~~
new_home.cpp:33:2: note: suggested alternative: 'main'
  cin>>N>>K>>Q;
  ^~~
  main
new_home.cpp:37:3: error: 'vec' was not declared in this scope
   vec[Y].pb(X);
   ^~~
new_home.cpp:41:6: error: 'vec' was not declared in this scope
   if(vec[A].empty())
      ^~~
new_home.cpp:44:5: error: 'cout' was not declared in this scope
     cout<<-1<<"\n";
     ^~~~
new_home.cpp:47:8: error: 'vec' was not declared in this scope
   sort(vec[A].begin(),vec[A].end());
        ^~~
new_home.cpp:47:3: error: 'sort' was not declared in this scope
   sort(vec[A].begin(),vec[A].end());
   ^~~~
new_home.cpp:47:3: note: suggested alternative: 'short'
   sort(vec[A].begin(),vec[A].end());
   ^~~~
   short
new_home.cpp:49:4: error: 'increasing' was not declared in this scope
    increasing.pb(mp(vec[A][B-1],(vec[A][B-1]+vec[A][B])/2));
    ^~~~~~~~~~
new_home.cpp:6:13: error: 'make_pair' was not declared in this scope
 #define mp  make_pair
             ^
new_home.cpp:49:18: note: in expansion of macro 'mp'
    increasing.pb(mp(vec[A][B-1],(vec[A][B-1]+vec[A][B])/2));
                  ^~
new_home.cpp:51:4: error: 'decreasing' was not declared in this scope
    decreasing.pb(mp(vec[A][B+1],(vec[A][B+1]+vec[A][B]+1)/2));  
    ^~~~~~~~~~
new_home.cpp:6:13: error: 'make_pair' was not declared in this scope
 #define mp  make_pair
             ^
new_home.cpp:51:18: note: in expansion of macro 'mp'
    decreasing.pb(mp(vec[A][B+1],(vec[A][B+1]+vec[A][B]+1)/2));  
                  ^~
new_home.cpp:52:3: error: 'increasing' was not declared in this scope
   increasing.pb(mp(vec[A].back(),INF));
   ^~~~~~~~~~
new_home.cpp:6:13: error: 'make_pair' was not declared in this scope
 #define mp  make_pair
             ^
new_home.cpp:52:17: note: in expansion of macro 'mp'
   increasing.pb(mp(vec[A].back(),INF));
                 ^~
new_home.cpp:53:3: error: 'decreasing' was not declared in this scope
   decreasing.pb(mp(*vec[A].begin(),0));
   ^~~~~~~~~~
new_home.cpp:54:9: error: 'max' was not declared in this scope
   Begin=max(Begin,*vec[A].begin());
         ^~~
new_home.cpp:54:9: note: suggested alternative: 'main'
   Begin=max(Begin,*vec[A].begin());
         ^~~
         main
new_home.cpp:55:7: error: 'min' was not declared in this scope
   End=min(End,vec[A].back());
       ^~~
new_home.cpp:55:7: note: suggested alternative: 'main'
   End=min(End,vec[A].back());
       ^~~
       main
new_home.cpp:57:7: error: 'increasing' was not declared in this scope
  sort(increasing.begin(),increasing.end());
       ^~~~~~~~~~
new_home.cpp:57:2: error: 'sort' was not declared in this scope
  sort(increasing.begin(),increasing.end());
  ^~~~
new_home.cpp:57:2: note: suggested alternative: 'short'
  sort(increasing.begin(),increasing.end());
  ^~~~
  short
new_home.cpp:58:7: error: 'decreasing' was not declared in this scope
  sort(decreasing.begin(),decreasing.end());
       ^~~~~~~~~~
new_home.cpp:61:5: error: 'max' was not declared in this scope
   l=max(pre+1,increasing[A].first);
     ^~~
new_home.cpp:61:5: note: suggested alternative: 'main'
   l=max(pre+1,increasing[A].first);
     ^~~
     main
new_home.cpp:65:3: error: 'fst' was not declared in this scope
   fst.pb(mp(l,r));
   ^~~
new_home.cpp:6:13: error: 'make_pair' was not declared in this scope
 #define mp  make_pair
             ^
new_home.cpp:65:10: note: in expansion of macro 'mp'
   fst.pb(mp(l,r));
          ^~
new_home.cpp:66:3: error: 'fst_' was not declared in this scope
   fst_.pb(increasing[A].first);
   ^~~~
new_home.cpp:72:5: error: 'min' was not declared in this scope
   l=min(pre-1,decreasing[A].first);
     ^~~
new_home.cpp:72:5: note: suggested alternative: 'main'
   l=min(pre-1,decreasing[A].first);
     ^~~
     main
new_home.cpp:76:3: error: 'sec' was not declared in this scope
   sec.pb(mp(r,l));
   ^~~
new_home.cpp:6:13: error: 'make_pair' was not declared in this scope
 #define mp  make_pair
             ^
new_home.cpp:76:10: note: in expansion of macro 'mp'
   sec.pb(mp(r,l));
          ^~
new_home.cpp:77:3: error: 'sec_' was not declared in this scope
   sec_.pb(decreasing[A].first);
   ^~~~
new_home.cpp:80:10: error: 'sec' was not declared in this scope
  reverse(sec.begin(),sec.end());
          ^~~
new_home.cpp:80:2: error: 'reverse' was not declared in this scope
  reverse(sec.begin(),sec.end());
  ^~~~~~~
new_home.cpp:81:10: error: 'sec_' was not declared in this scope
  reverse(sec_.begin(),sec_.end());
          ^~~~
new_home.cpp:100:18: error: 'fst' was not declared in this scope
   int low=0,high=fst.size()-1,mid;
                  ^~~
new_home.cpp:103:4: error: 'mid' was not declared in this scope
    mid=(low+high)/2;
    ^~~
new_home.cpp:103:4: note: suggested alternative: 'main'
    mid=(low+high)/2;
    ^~~
    main
new_home.cpp:106:23: error: 'fst_' was not declared in this scope
     res=max(res,abs(X-fst_[mid]));
                       ^~~~
new_home.cpp:106:17: error: 'abs' was not declared in this scope
     res=max(res,abs(X-fst_[mid]));
                 ^~~
new_home.cpp:106:9: error: 'max' was not declared in this scope
     res=max(res,abs(X-fst_[mid]));
         ^~~
new_home.cpp:106:9: note: suggested alternative: 'main'
     res=max(res,abs(X-fst_[mid]));
         ^~~
         main
new_home.cpp:117:4: error: 'mid' was not declared in this scope
    mid=(low+high)/2;
    ^~~
new_home.cpp:117:4: note: suggested alternative: 'main'
    mid=(low+high)/2;
    ^~~
    main
new_home.cpp:120:17: error: 'abs' was not declared in this scope
     res=max(res,abs(sec_[mid]-X));
                 ^~~
new_home.cpp:120:9: error: 'max' was not declared in this scope
     res=max(res,abs(sec_[mid]-X));
         ^~~
new_home.cpp:120:9: note: suggested alternative: 'main'
     res=max(res,abs(sec_[mid]-X));
         ^~~
         main
new_home.cpp:128:3: error: 'cout' was not declared in this scope
   cout<<res<<"\n";
   ^~~~