#pragma GCC optimize("Ofast")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include "xylophone.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define e1 first
#define e2 second
#define uint uint_fast64_t
#define ll int_fast64_t
#define ull uint_fast64_t
#define int16 int_fast16_t
#define uint16 uint_fast16_t
#define int32 int_fast32_t
#define uint32 uint_fast32_t
#define int64 int_fast64_t
#define uint64 uint_fast64_t
#define ld long double
#define float long double
#define size(x) (int)x.size()
#define satori int testCases; cin>>testCases; while(testCases--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(r) begin(r),end(r)
#define rall(r) rbegin(r),rend(r)
#define time chrono::high_resolution_clock().now().time_since_epoch().count()
#define elapsed(__begin,__end) (__end-__begin)/CLOCKS_PER_SEC
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
float pi=3.14159265358979323846;
const int MAXN=5e3+10,inf=1e9+2137;
/*
int a[MAXN],b[MAXN];
int query(int l,int r)
{
int mn=inf,mx=-inf;
for(int i=l;i<=r;i++)
mn=min(mn,a[i]),mx=max(mx,a[i]);
return mx-mn;
}
int answer(int i,int v)
{
b[i]=v;
}
*/
int h[MAXN],d[MAXN],t[MAXN];
void solve(int n)
{
for(int i=1;i<n;i++)
d[i]=query(i,i+1);
for(int i=1;i<n-1;i++)
t[i]=query(i,i+2);
h[2]=d[1];
for(int i=3;i<=n;i++)
{
if(d[i-2]>d[i-1])
{
if(h[i-2]>h[i-1])
{
if(t[i-2]>d[i-2])
h[i]=h[i-1]-d[i-1];
else
h[i]=h[i-1]+d[i-1];
}
else
{
if(t[i-2]>d[i-2])
h[i]=h[i-1]+d[i-1];
else
h[i]=h[i-1]-d[i-1];
}
}
else
{
if(h[i-2]>h[i-1])
{
if(t[i-2]==d[i-2]+d[i-1])
h[i]=h[i-1]-d[i-1];
else
h[i]=h[i-1]+d[i-1];
}
else
{
if(t[i-2]==d[i-2]+d[i-1])
h[i]=h[i-1]+d[i-1];
else
h[i]=h[i-1]-d[i-1];
}
}
}
int lp=1,rp=1;
for(int i=2;i<=n;i++)
lp=(h[i]<h[lp]?i:lp),rp=(h[i]>h[rp]?i:rp);
if(rp<lp)
for(int i=1;i<=n;i++)
h[i]*=-1;
int mn=0;
for(int i=2;i<=n;i++)
mn=min(mn,h[i]);
for(int i=1;i<=n;i++)
h[i]+=-mn+1;
for(int i=1;i<=n;i++)
answer(i,h[i]);
}
/*
int main()
{
a[1]=2,a[2]=1,a[3]=5,a[4]=3,a[5]=4;
solve(5);
for(int i=1;i<=5;i++)
cout<<b[i]<<' ';
}
*/
Compilation message
xylophone.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
2 | #pragma GCC optimization ("O3")
|
xylophone.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
384 KB |
Output is correct |
18 |
Correct |
18 ms |
376 KB |
Output is correct |
19 |
Correct |
19 ms |
376 KB |
Output is correct |
20 |
Correct |
21 ms |
504 KB |
Output is correct |
21 |
Correct |
19 ms |
376 KB |
Output is correct |
22 |
Correct |
16 ms |
384 KB |
Output is correct |
23 |
Correct |
17 ms |
376 KB |
Output is correct |
24 |
Correct |
16 ms |
376 KB |
Output is correct |
25 |
Correct |
20 ms |
384 KB |
Output is correct |
26 |
Correct |
18 ms |
384 KB |
Output is correct |
27 |
Correct |
17 ms |
384 KB |
Output is correct |
28 |
Correct |
15 ms |
384 KB |
Output is correct |
29 |
Correct |
18 ms |
376 KB |
Output is correct |
30 |
Correct |
19 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
384 KB |
Output is correct |
18 |
Correct |
18 ms |
376 KB |
Output is correct |
19 |
Correct |
19 ms |
376 KB |
Output is correct |
20 |
Correct |
21 ms |
504 KB |
Output is correct |
21 |
Correct |
19 ms |
376 KB |
Output is correct |
22 |
Correct |
16 ms |
384 KB |
Output is correct |
23 |
Correct |
17 ms |
376 KB |
Output is correct |
24 |
Correct |
16 ms |
376 KB |
Output is correct |
25 |
Correct |
20 ms |
384 KB |
Output is correct |
26 |
Correct |
18 ms |
384 KB |
Output is correct |
27 |
Correct |
17 ms |
384 KB |
Output is correct |
28 |
Correct |
15 ms |
384 KB |
Output is correct |
29 |
Correct |
18 ms |
376 KB |
Output is correct |
30 |
Correct |
19 ms |
376 KB |
Output is correct |
31 |
Correct |
38 ms |
536 KB |
Output is correct |
32 |
Correct |
31 ms |
376 KB |
Output is correct |
33 |
Correct |
82 ms |
384 KB |
Output is correct |
34 |
Correct |
79 ms |
504 KB |
Output is correct |
35 |
Correct |
89 ms |
384 KB |
Output is correct |
36 |
Correct |
93 ms |
376 KB |
Output is correct |
37 |
Correct |
80 ms |
384 KB |
Output is correct |
38 |
Correct |
91 ms |
376 KB |
Output is correct |
39 |
Correct |
98 ms |
504 KB |
Output is correct |
40 |
Correct |
94 ms |
376 KB |
Output is correct |
41 |
Correct |
96 ms |
376 KB |
Output is correct |
42 |
Correct |
53 ms |
384 KB |
Output is correct |
43 |
Correct |
85 ms |
376 KB |
Output is correct |
44 |
Correct |
86 ms |
512 KB |
Output is correct |
45 |
Correct |
81 ms |
376 KB |
Output is correct |
46 |
Correct |
93 ms |
376 KB |
Output is correct |
47 |
Correct |
110 ms |
516 KB |
Output is correct |
48 |
Correct |
88 ms |
380 KB |
Output is correct |
49 |
Correct |
95 ms |
376 KB |
Output is correct |
50 |
Correct |
82 ms |
504 KB |
Output is correct |
51 |
Correct |
103 ms |
376 KB |
Output is correct |
52 |
Correct |
99 ms |
376 KB |
Output is correct |
53 |
Correct |
68 ms |
504 KB |
Output is correct |
54 |
Correct |
91 ms |
384 KB |
Output is correct |
55 |
Correct |
107 ms |
376 KB |
Output is correct |
56 |
Correct |
102 ms |
376 KB |
Output is correct |
57 |
Correct |
92 ms |
384 KB |
Output is correct |
58 |
Correct |
51 ms |
376 KB |
Output is correct |
59 |
Correct |
85 ms |
504 KB |
Output is correct |
60 |
Correct |
91 ms |
504 KB |
Output is correct |