Submission #58370

# Submission time Handle Problem Language Result Execution time Memory
58370 2018-07-17T15:06:54 Z khohko Xylophone (JOI18_xylophone) C++17
100 / 100
121 ms 844 KB
#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]);
}


Compilation message

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 time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 416 KB Output is correct
5 Correct 5 ms 416 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 2 ms 488 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 4 ms 568 KB Output is correct
12 Correct 4 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 5 ms 568 KB Output is correct
15 Correct 4 ms 568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 416 KB Output is correct
5 Correct 5 ms 416 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 2 ms 488 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 4 ms 568 KB Output is correct
12 Correct 4 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 5 ms 568 KB Output is correct
15 Correct 4 ms 568 KB Output is correct
16 Correct 7 ms 568 KB Output is correct
17 Correct 12 ms 572 KB Output is correct
18 Correct 24 ms 572 KB Output is correct
19 Correct 12 ms 572 KB Output is correct
20 Correct 12 ms 572 KB Output is correct
21 Correct 27 ms 572 KB Output is correct
22 Correct 20 ms 700 KB Output is correct
23 Correct 18 ms 700 KB Output is correct
24 Correct 16 ms 700 KB Output is correct
25 Correct 20 ms 700 KB Output is correct
26 Correct 19 ms 700 KB Output is correct
27 Correct 25 ms 700 KB Output is correct
28 Correct 16 ms 700 KB Output is correct
29 Correct 19 ms 700 KB Output is correct
30 Correct 19 ms 700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 308 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 416 KB Output is correct
5 Correct 5 ms 416 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 2 ms 488 KB Output is correct
8 Correct 3 ms 492 KB Output is correct
9 Correct 4 ms 492 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 4 ms 568 KB Output is correct
12 Correct 4 ms 568 KB Output is correct
13 Correct 4 ms 568 KB Output is correct
14 Correct 5 ms 568 KB Output is correct
15 Correct 4 ms 568 KB Output is correct
16 Correct 7 ms 568 KB Output is correct
17 Correct 12 ms 572 KB Output is correct
18 Correct 24 ms 572 KB Output is correct
19 Correct 12 ms 572 KB Output is correct
20 Correct 12 ms 572 KB Output is correct
21 Correct 27 ms 572 KB Output is correct
22 Correct 20 ms 700 KB Output is correct
23 Correct 18 ms 700 KB Output is correct
24 Correct 16 ms 700 KB Output is correct
25 Correct 20 ms 700 KB Output is correct
26 Correct 19 ms 700 KB Output is correct
27 Correct 25 ms 700 KB Output is correct
28 Correct 16 ms 700 KB Output is correct
29 Correct 19 ms 700 KB Output is correct
30 Correct 19 ms 700 KB Output is correct
31 Correct 43 ms 716 KB Output is correct
32 Correct 61 ms 716 KB Output is correct
33 Correct 58 ms 716 KB Output is correct
34 Correct 87 ms 716 KB Output is correct
35 Correct 94 ms 716 KB Output is correct
36 Correct 115 ms 716 KB Output is correct
37 Correct 81 ms 716 KB Output is correct
38 Correct 86 ms 716 KB Output is correct
39 Correct 93 ms 724 KB Output is correct
40 Correct 101 ms 844 KB Output is correct
41 Correct 75 ms 844 KB Output is correct
42 Correct 85 ms 844 KB Output is correct
43 Correct 88 ms 844 KB Output is correct
44 Correct 88 ms 844 KB Output is correct
45 Correct 52 ms 844 KB Output is correct
46 Correct 97 ms 844 KB Output is correct
47 Correct 93 ms 844 KB Output is correct
48 Correct 108 ms 844 KB Output is correct
49 Correct 87 ms 844 KB Output is correct
50 Correct 121 ms 844 KB Output is correct
51 Correct 58 ms 844 KB Output is correct
52 Correct 90 ms 844 KB Output is correct
53 Correct 84 ms 844 KB Output is correct
54 Correct 96 ms 844 KB Output is correct
55 Correct 94 ms 844 KB Output is correct
56 Correct 83 ms 844 KB Output is correct
57 Correct 106 ms 844 KB Output is correct
58 Correct 82 ms 844 KB Output is correct
59 Correct 78 ms 844 KB Output is correct
60 Correct 88 ms 844 KB Output is correct