답안 #25706

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25706 2017-06-23T17:43:37 Z gs14004 유괴 2 (JOI17_abduction2) C++11
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

struct line{
	int pos, val, axis;
	bool operator<(const line &l)const{
		return val < l.val;
	}
}a[100005];

int n, m, q;
int st[100005], ed[100005];
lint ldp[100005], rdp[100005];
int rev[2][50005];

lint solve(int x, int y, int cs){
	memset(ldp, 0, sizeof(ldp));
	memset(rdp, 0, sizeof(rdp));
	int l[2] = {0, 0}, h[2] = {n-1, m-1};
	lint ret = 0;
	for(int i=0; i<n+m; i++){
		st[i] = l[a[i].axis ^ 1], ed[i] = h[a[i].axis ^ 1];
		if(rev[a[i].axis ^ 1][ed[i]] < i){
			int r = rev[a[i].axis ^ 1][ed[i]];
			rdp[i] = max(ldp[r] + abs(st[r] - a[i].pos), rdp[r] + abs(ed[r] - a[i].pos));
		}
		if(rev[a[i].axis ^ 1][st[i]] < i){
			int r = rev[a[i].axis ^ 1][st[i]];
			ldp[i] = max(ldp[r] + abs(st[r] - a[i].pos), rdp[r] + abs(ed[r] - a[i].pos));
		}
		if(a[i].axis == 0){
			if(cs & 1){
				if(x <= a[i].pos) xh = min(xh, a[i].pos);
				else xl = max(xl, a[i].pos);
			}
			else{
				if(x < a[i].pos) xh = min(xh, a[i].pos);
				else xl = max(xl, a[i].pos);
			}
			if(a[i].pos == x){
				ret = max({ret, ldp[i] + abs(st[i] - y), rdp[i] + abs(ed[i] - y)});
			}
		}
		else{
			if(cs & 2){
				if(y <= a[i].pos) yh = min(yh, a[i].pos);
				else yl = max(yl, a[i].pos);
			}
			else{
				if(y < a[i].pos) yh = min(yh, a[i].pos);
				else yl = max(yl, a[i].pos);
			}
			if(a[i].pos == y){
				ret = max({ret, ldp[i] + abs(st[i] - x), rdp[i] + abs(ed[i] - x)});
			}
		}
	}
	return ret;
}

int main(){
	scanf("%d %d %d",&n,&m,&q);
	for(int i=0; i<n; i++){
		scanf("%d",&a[i].val);
		a[i].pos = i;
		a[i].axis = 0;
	}
	for(int i=0; i<m; i++){
		scanf("%d",&a[i+n].val);
		a[i+n].pos = i;
		a[i+n].axis = 1;
	}
	sort(a, a+n+m);
	reverse(a, a+n+m);
	for(int i=0; i<n+m; i++){
		rev[a[i].axis][a[i].pos] = i;
	}
	for(int i=0; i<q; i++){
		int x, y;
		scanf("%d %d",&x,&y);
		lint ret = 0;
		for(int j=0; j<4; j++) ret = max(ret, solve(x-1, y-1, j));
		printf("%lld\n", ret);
	}
}

Compilation message

abduction2.cpp: In function 'lint solve(int, int, int)':
abduction2.cpp:36:23: error: 'xh' was not declared in this scope
     if(x <= a[i].pos) xh = min(xh, a[i].pos);
                       ^
abduction2.cpp:37:10: error: 'xl' was not declared in this scope
     else xl = max(xl, a[i].pos);
          ^
abduction2.cpp:40:22: error: 'xh' was not declared in this scope
     if(x < a[i].pos) xh = min(xh, a[i].pos);
                      ^
abduction2.cpp:41:10: error: 'xl' was not declared in this scope
     else xl = max(xl, a[i].pos);
          ^
abduction2.cpp:49:23: error: 'yh' was not declared in this scope
     if(y <= a[i].pos) yh = min(yh, a[i].pos);
                       ^
abduction2.cpp:50:10: error: 'yl' was not declared in this scope
     else yl = max(yl, a[i].pos);
          ^
abduction2.cpp:53:22: error: 'yh' was not declared in this scope
     if(y < a[i].pos) yh = min(yh, a[i].pos);
                      ^
abduction2.cpp:54:10: error: 'yl' was not declared in this scope
     else yl = max(yl, a[i].pos);
          ^
abduction2.cpp: In function 'int main()':
abduction2.cpp:65:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&q);
                            ^
abduction2.cpp:67:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i].val);
                        ^
abduction2.cpp:72:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i+n].val);
                          ^
abduction2.cpp:83:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&x,&y);
                       ^