제출 #58370

#제출 시각아이디문제언어결과실행 시간메모리
58370khohkoXylophone (JOI18_xylophone)C++17
100 / 100
121 ms844 KiB
#include <bits/stdc++.h>
#include "xylophone.h"
#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define pb push_back
//#define mp make_pair
#define fr first
#define sc second
#define MAX ((ll)(1e17+100))
#define MX ((ll)(1e5+100))
#define ARRS ((ll)(1e6+100))
#define ARS ((ll)(1e3+100))
#define HS ((ll)(233))
#define MOD ((ll)(1e9+7))
#define EP ((double)(1e-9))
#define LG 21
#define mul(a,b) a=((a)*(b))%MOD
using namespace std;


ll a[ARRS];

void solve(int n) {
	ll l,r;
	a[1]=0;
	a[2]=query(1,2);
	for(int i=3; i<=n; i++){
		ll k,p;
		k=query(i-2,i);
		p=query(i-1,i);
		//cout<<k<<" "<<p<<endl;
		if(a[i-2]<a[i-1]){
			if(k==p+abs(a[i-1]-a[i-2]))
				a[i]=a[i-1]+p;
			else a[i]=a[i-1]-p;
		}
		else {
			if(k==p+abs(a[i-1]-a[i-2]))
				a[i]=a[i-1]-p;
			else a[i]=a[i-1]+p;
		}
	}
	pair<ll,ll> mn,mx;
	mn.fr=MAX;
	mx.fr=-MAX;
	for(int i=1; i<=n; i++){
		mn=min(mn,{a[i],i});
		mx=max(mx,{a[i],i});
	}
	ll t;
	if(mn.sc>mx.sc){
		for(int i=1; i<=n; i++)
			a[i]=-a[i];
		t=mx.fr;
	}
	else t=-mn.fr;
	//for(int i=1; i<=n; i++)
		//cout<<a[i]<<" ";
	//cout<<endl;
	//cout<<mn.fr<<" "<<mn.sc<<endl;
	//cout<<mx.fr<<" "<<mx.sc<<endl;
	//cout<<t<<endl;
	
	for(int i=1; i<=n; i++)a[i]+=t+1;
	//for(int i=1; i<=n; i++)
		//cout<<a[i]<<" ";
	//cout<<endl;
	for(int i = 1; i <= n; i++) 
		answer(i, a[i]);
}


컴파일 시 표준 에러 (stderr) 메시지

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:25:5: warning: unused variable 'l' [-Wunused-variable]
  ll l,r;
     ^
xylophone.cpp:25:7: warning: unused variable 'r' [-Wunused-variable]
  ll l,r;
       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...