답안 #895856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895856 2023-12-31T00:12:41 Z starchan Xylophone (JOI18_xylophone) C++17
컴파일 오류
0 ms 0 KB
#include "xylophone.h"
#include<bits/stdc++.h>
using namespace std;
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)3e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
void solve(int n)
{
	if(n == 2)
	{
		answer(1, 1);
		answer(2, 2);
		return;
	}
	int l = 1;
	int r = n;
	while(l < r)
	{
		int m = (l+r)/2;
		int t = query(m, n);
		if(t != (n-1))
			r = m;
		else
			l = m+1;
	}
	l--;
	vector<int> d(n+1);
	vector<int> d2(n+1);
	vector<int> a(n+1);
	for(int i = 2; i <= n; i++)
		d[i] = query(i-1, i);
	a[l] = 1;
	if(l >= 2)
		a[l-1] = 1+d[l];
	a[l+1] = 1+d[l+1];
	for(int i = 3; i <= n; i++)
		d2[i] = query(i-2, i);
	for(int i = l+2; i <= n; i++)
	{
		if(d2[i] == (d1[i]+d1[i-1]))
		{
			if(a[i-2] > a[i-1])
				a[i] = a[i-1]-d1[i];
			else
				a[i] = a[i-1]+d1[i];
		}
		else
		{
			if(a[i-2] > a[i-1])
				a[i] = a[i-1]+d1[i];
			else
				a[i] = a[i-1]-d1[i];
		}
	}
	for(int i = l-2; i >= 1; i--)
	{
		//a[i] a[i+1] a[i+2]
		if(d2[i+2] == (d[i+2]+d[i+1]))
		{
			if(a[i+1] < a[i+2])
				a[i] = a[i+1]-d[i+1];
			else
				a[i] = a[i+1]+d[i+1];
		}
		else
		{
			if(a[i+1] < a[i+2])
				a[i] = a[i+1]+d[i+1];
			else
				a[i] = a[i+1]-d[i+1];
		}
	}
	for(int i = 1; i <= n; i++)
		answer(i, a[i]);
	return;
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:45:16: error: 'd1' was not declared in this scope; did you mean 'd2'?
   45 |   if(d2[i] == (d1[i]+d1[i-1]))
      |                ^~
      |                d2