Submission #263479

# Submission time Handle Problem Language Result Execution time Memory
263479 2020-08-13T17:38:20 Z Aaeria Xylophone (JOI18_xylophone) C++14
100 / 100
101 ms 636 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std; using namespace __gnu_pbds;
//#pragma GCC optimize("Ofast") //#pragma GCC optimize "unroll-loops" //#pragma GCC optimize "prefetch-loop-arrays" //#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,aes,sse4a,sse4.1,sse4.2,mmx,popcnt,tune=native"
#define foru(i,a,b) for(int i=(a);i<(b);i++)
#define ford(i,a,b) for(int i=(a);i>=(b);i--)
#define fori(a,b) foru(i,a,b)
#define forj(a,b) foru(j,a,b)
#define fork(a,b) foru(k,a,b)
#define seto(x,i) memset(x,i,sizeof x)
#define pf first
#define ps second
#define pb push_back
#define eb emplace_back
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define clz __builtin_clz
#define clzll __builtin_clzll
#define ctz __builtin_ctz
#define ctzll __builtin_ctzll
#define P2(x) (1LL<<(x))
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#if __SIZEOF_INT128__
    typedef __int128_t i128; typedef __uint128_t ui128;
#else
    typedef long long i128; typedef unsigned long long ui128;
#endif
typedef int64_t ll;  typedef uint64_t ull; typedef int8_t byte; typedef long double lld;
typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<lld,lld> pdd;
template<typename T1,typename T2> using ordered_map=tree<T1,T2,less<T1>,rb_tree_tag,tree_order_statistics_node_update>;
template<typename T1> using ordered_set=ordered_map<T1,null_type>;
const int inf=0x3f3f3f3f,MOD=1e9+7; const ll INF=0x3f3f3f3f3f3f3f3f; const lld PI=acos((lld)-1);
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll fpow(ll a,ll b){if(!b) return 1; ll t=fpow(a,b/2); if(b&1) return t*t%MOD*a%MOD; return t*t%MOD;}
const ll SEED=chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count();
mt19937 randgen(SEED); int randint(int a, int b){return uniform_int_distribution<int>(a,b)(randgen);} ll randll(ll a, ll b){return uniform_int_distribution<ll>(a,b)(randgen);}
template<class T1,class T2>constexpr const auto _min(const T1&x,const T2&y){return x<y?x:y;} template<class T,class...Ts>constexpr auto _min(const T&x,const Ts&...xs){return _min(x,_min(xs...));}
template<class T1,class T2>constexpr const auto _max(const T1&x,const T2&y){return x>y?x:y;} template<class T,class...Ts>constexpr auto _max(const T&x,const Ts&...xs){return _max(x,_max(xs...));}
#define min(...) _min(__VA_ARGS__)
#define max(...) _max(__VA_ARGS__)
struct chash{
    static ll splitmix64(ll x){x+=0x9e3779b97f4a7c15; x=(x^(x>>30))*0xbf58476d1ce4e5b9; x=(x^(x>>27))*0x94d049bb133111eb; return x^(x>>31);}
    template<class T> size_t operator()(const T &x) const{return splitmix64(hash<T>()(x)+SEED);}
    template<class T1,class T2> size_t operator()(const pair<T1,T2>&x)const{return 31*operator()(x.first)+operator()(x.second);}
};
#define nl "\n"

const int N=5010,M=MOD;
int pitch[N];
int n,bar[N],x,y;
int query(int l,int r);
void answer(int i,int x);
/*
int query(int l,int r){
    int mi=inf,ma=-inf;
    fori(l,r+1) mi=min(mi,pitch[i]),ma=max(ma,pitch[i]);
    return abs(mi-ma);
}
void answer(int i,int x){
    cout<<i<<" "<<pitch[i]<<" "<<x<<endl;
}
//*/
void solve(int _n){
    n=_n;
    bar[2]=query(1,2);
    fori(3,n+1){
        bar[i]=query(i-1,i);
        x=query(i-2,i);
        if(bar[i-1]<0) bar[i]=-bar[i];
        if(x!=abs(bar[i]+bar[i-1])) bar[i]=-bar[i];
    }
    x=y=0;
    fori(1,n+1){
        bar[i]+=bar[i-1];
        if(!x||bar[i]<bar[x]) x=i;
        if(!y||bar[i]>bar[y]) y=i;
    }
    if(x<y){
        x=bar[x];
        fori(1,n+1) bar[i]-=x-1;
    }
    else{
        x=bar[y];
        fori(1,n+1) bar[i]=x-bar[i]+1;
    }
    fori(1,n+1) answer(i,bar[i]);

}
/*
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen("01-03.txt", "r", stdin); //freopen("", "w", stdout);
    cin>>n;
    fori(1,n+1) cin>>pitch[i];
    solve(n);
    return 0;
}
/**

*/

Compilation message

xylophone.cpp:100:1: warning: "/*" within comment [-Wcomment]
  100 | /**
      |
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 8 ms 384 KB Output is correct
18 Correct 17 ms 384 KB Output is correct
19 Correct 18 ms 384 KB Output is correct
20 Correct 18 ms 384 KB Output is correct
21 Correct 18 ms 384 KB Output is correct
22 Correct 16 ms 384 KB Output is correct
23 Correct 18 ms 384 KB Output is correct
24 Correct 19 ms 384 KB Output is correct
25 Correct 21 ms 384 KB Output is correct
26 Correct 10 ms 388 KB Output is correct
27 Correct 18 ms 384 KB Output is correct
28 Correct 19 ms 384 KB Output is correct
29 Correct 20 ms 384 KB Output is correct
30 Correct 17 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 8 ms 384 KB Output is correct
18 Correct 17 ms 384 KB Output is correct
19 Correct 18 ms 384 KB Output is correct
20 Correct 18 ms 384 KB Output is correct
21 Correct 18 ms 384 KB Output is correct
22 Correct 16 ms 384 KB Output is correct
23 Correct 18 ms 384 KB Output is correct
24 Correct 19 ms 384 KB Output is correct
25 Correct 21 ms 384 KB Output is correct
26 Correct 10 ms 388 KB Output is correct
27 Correct 18 ms 384 KB Output is correct
28 Correct 19 ms 384 KB Output is correct
29 Correct 20 ms 384 KB Output is correct
30 Correct 17 ms 384 KB Output is correct
31 Correct 49 ms 384 KB Output is correct
32 Correct 48 ms 384 KB Output is correct
33 Correct 84 ms 384 KB Output is correct
34 Correct 94 ms 504 KB Output is correct
35 Correct 90 ms 384 KB Output is correct
36 Correct 96 ms 384 KB Output is correct
37 Correct 97 ms 504 KB Output is correct
38 Correct 87 ms 384 KB Output is correct
39 Correct 97 ms 384 KB Output is correct
40 Correct 74 ms 504 KB Output is correct
41 Correct 89 ms 384 KB Output is correct
42 Correct 97 ms 384 KB Output is correct
43 Correct 92 ms 384 KB Output is correct
44 Correct 98 ms 380 KB Output is correct
45 Correct 94 ms 384 KB Output is correct
46 Correct 96 ms 504 KB Output is correct
47 Correct 77 ms 388 KB Output is correct
48 Correct 92 ms 396 KB Output is correct
49 Correct 88 ms 384 KB Output is correct
50 Correct 49 ms 388 KB Output is correct
51 Correct 91 ms 384 KB Output is correct
52 Correct 90 ms 392 KB Output is correct
53 Correct 85 ms 400 KB Output is correct
54 Correct 96 ms 384 KB Output is correct
55 Correct 91 ms 504 KB Output is correct
56 Correct 87 ms 384 KB Output is correct
57 Correct 91 ms 384 KB Output is correct
58 Correct 88 ms 636 KB Output is correct
59 Correct 101 ms 384 KB Output is correct
60 Correct 92 ms 384 KB Output is correct