Submission #201996

# Submission time Handle Problem Language Result Execution time Memory
201996 2020-02-13T02:36:19 Z Segtree Xylophone (JOI18_xylophone) C++14
100 / 100
103 ms 436 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include"xylophone.h"
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
/*ll val[5010],cnt;
ll query(ll s,ll t){
    cnt++;
    ll ma=-1e17,mi=1e17;
    for(int i=s;i<=t;i++){
	chmax(ma,val[i]);
	chmin(mi,val[i]);
    }
    return ma-mi;
}
void answer(ll i,ll x){
    cout<<i<<":"<<x<<endl;
}*/
void solve(int n){
    ll a[5010];
    a[1]=0,a[2]=query(1,2);
    for(int i=3;i<=n;i++){
	ll x=query(i-1,i);
	ll y=query(i-2,i);
	if(abs(a[i-2]-a[i-1])+x==y){
	    if(a[i-2]<a[i-1])a[i]=a[i-1]+x;
	    else a[i]=a[i-1]-x;
	}
	else{
	    if(a[i-2]<a[i-1])a[i]=a[i-1]-x;
	    else a[i]=a[i-1]+x;
	}
    }
    ll mi=1e17,ma=-1e17,pmi,pma;
    for(int i=1;i<=n;i++){
	if(mi>a[i])mi=a[i],pmi=i;
	if(ma<a[i])ma=a[i],pma=i;
    }
    for(int i=1;i<=n;i++)a[i]=a[i]-mi+1;
    if(pmi>pma)for(int i=1;i<=n;i++)a[i]=n+1-a[i];
    for(int i=1;i<=n;i++){
	answer(i,a[i]);
    }
}
/*int main(){
    ll n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>val[i];
    cnt=0;
    solve(n);
    cout<<"cnt="<<cnt<<endl;
}*/


Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:51:5: warning: 'pma' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if(pmi>pma)for(int i=1;i<=n;i++)a[i]=n+1-a[i];
     ^~
xylophone.cpp:51:5: warning: 'pmi' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 6 ms 248 KB Output is correct
4 Correct 7 ms 280 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 7 ms 376 KB Output is correct
7 Correct 7 ms 248 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 7 ms 376 KB Output is correct
10 Correct 6 ms 248 KB Output is correct
11 Correct 6 ms 248 KB Output is correct
12 Correct 7 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 7 ms 248 KB Output is correct
15 Correct 7 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 6 ms 248 KB Output is correct
4 Correct 7 ms 280 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 7 ms 376 KB Output is correct
7 Correct 7 ms 248 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 7 ms 376 KB Output is correct
10 Correct 6 ms 248 KB Output is correct
11 Correct 6 ms 248 KB Output is correct
12 Correct 7 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 7 ms 248 KB Output is correct
15 Correct 7 ms 248 KB Output is correct
16 Correct 10 ms 248 KB Output is correct
17 Correct 16 ms 248 KB Output is correct
18 Correct 22 ms 248 KB Output is correct
19 Correct 24 ms 376 KB Output is correct
20 Correct 21 ms 328 KB Output is correct
21 Correct 23 ms 376 KB Output is correct
22 Correct 26 ms 376 KB Output is correct
23 Correct 17 ms 376 KB Output is correct
24 Correct 22 ms 252 KB Output is correct
25 Correct 29 ms 376 KB Output is correct
26 Correct 24 ms 384 KB Output is correct
27 Correct 25 ms 380 KB Output is correct
28 Correct 20 ms 248 KB Output is correct
29 Correct 20 ms 376 KB Output is correct
30 Correct 20 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 248 KB Output is correct
3 Correct 6 ms 248 KB Output is correct
4 Correct 7 ms 280 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 7 ms 376 KB Output is correct
7 Correct 7 ms 248 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 7 ms 376 KB Output is correct
10 Correct 6 ms 248 KB Output is correct
11 Correct 6 ms 248 KB Output is correct
12 Correct 7 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 7 ms 248 KB Output is correct
15 Correct 7 ms 248 KB Output is correct
16 Correct 10 ms 248 KB Output is correct
17 Correct 16 ms 248 KB Output is correct
18 Correct 22 ms 248 KB Output is correct
19 Correct 24 ms 376 KB Output is correct
20 Correct 21 ms 328 KB Output is correct
21 Correct 23 ms 376 KB Output is correct
22 Correct 26 ms 376 KB Output is correct
23 Correct 17 ms 376 KB Output is correct
24 Correct 22 ms 252 KB Output is correct
25 Correct 29 ms 376 KB Output is correct
26 Correct 24 ms 384 KB Output is correct
27 Correct 25 ms 380 KB Output is correct
28 Correct 20 ms 248 KB Output is correct
29 Correct 20 ms 376 KB Output is correct
30 Correct 20 ms 248 KB Output is correct
31 Correct 44 ms 376 KB Output is correct
32 Correct 65 ms 376 KB Output is correct
33 Correct 78 ms 376 KB Output is correct
34 Correct 82 ms 436 KB Output is correct
35 Correct 94 ms 376 KB Output is correct
36 Correct 91 ms 376 KB Output is correct
37 Correct 101 ms 376 KB Output is correct
38 Correct 103 ms 248 KB Output is correct
39 Correct 74 ms 376 KB Output is correct
40 Correct 95 ms 376 KB Output is correct
41 Correct 96 ms 376 KB Output is correct
42 Correct 93 ms 376 KB Output is correct
43 Correct 97 ms 252 KB Output is correct
44 Correct 100 ms 376 KB Output is correct
45 Correct 94 ms 376 KB Output is correct
46 Correct 85 ms 376 KB Output is correct
47 Correct 94 ms 376 KB Output is correct
48 Correct 99 ms 376 KB Output is correct
49 Correct 89 ms 376 KB Output is correct
50 Correct 76 ms 376 KB Output is correct
51 Correct 100 ms 376 KB Output is correct
52 Correct 90 ms 376 KB Output is correct
53 Correct 91 ms 376 KB Output is correct
54 Correct 81 ms 376 KB Output is correct
55 Correct 92 ms 376 KB Output is correct
56 Correct 103 ms 252 KB Output is correct
57 Correct 91 ms 376 KB Output is correct
58 Correct 87 ms 376 KB Output is correct
59 Correct 90 ms 376 KB Output is correct
60 Correct 92 ms 348 KB Output is correct