//cre:cpptowin
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define db double
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb push_back
#define en cout<<"\n";
#define int long long
#define inf 1000000000
#define pii pair<int,int>
#define vii vector<pii>
#define eps 1e-9
#define bit(i,j) ((i>>j)&1)
#define offbit(i,j) (i^(1<<j))
#define onbit(i,j) (i|(j<<1))
#define vi vector<int>
#define vvi vector<vector<int>>
#define checkfile(FiLeNaMe) { if(fopen(FiLeNaMe".inp","r")) freopen(FiLeNaMe".inp","r",stdin),freopen(FiLeNaMe".out","w",stdout); }
template <typename T1, typename T2> bool minimize(T1 &a, T2 b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
using namespace std;
int par[maxn],tp[maxn];
int find(int u)
{
return u==par[u]?u:par[u]=find(par[u]);
}
//int find(int u)
//{
// return par[u]?par[u]=find(par[u]):u;
//}
pii a[maxn];
int n,res,cnt,arr[maxn];
main()
{
freopen("DUATHLON.INP","r",stdin);
freopen("DUATHLON.OUT","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n;
fo(i,1,n) cin>>arr[i];
// fo(i,1,n) cout<<arr[i]<<' ';
// en;
fo(i,1,n) a[i].fi=arr[i],a[i].se=i;
sort(a+1,a+n+1,greater<pii>());
fo(i,0,n+1) par[i]=i;
tp[0]=0;
tp[n+1]=n+1;
fo(i,1,n) tp[i]=-1;
bool ok=1;
fo(i,2,n) if(arr[i]!=arr[i-1]) ok=0;
// cout<<ok<<' ';
if(ok)
{
cout<<0;return 0;
}
fo(i,1,n)
{
tp[a[i].se]=a[i].se;
// cnt+=2;
// if (tp[a[i].se-1]!=-1)
// {
// int x=find(a[i].se-1);
// tp[a[i].se]=par[a[i].se]=x; cnt--;
// }
// if (tp[a[i].se+1]!=-1)
// {
// int x=find(a[i].se+1);
// tp[a[i].se]=par[a[i].se]=x;
// cnt--;
// }
if(a[i].se==1)
{
cnt++;
if(tp[a[i].se+1]!=-1) cnt-=2;
}
else if(a[i].se==n)
{
cnt++;
if(tp[a[i].se-1]!=-1) cnt-=2;
}
else if((tp[a[i].se+1]==-1||tp[a[i].se-1]==-1)&&(tp[a[i].se+1]+tp[a[i].se-1]!=-2)) ;
else if(tp[a[i].se+1]==-1&&tp[a[i].se-1]==-1) cnt+=2;
else if(tp[a[i].se+1]!=-1&&tp[a[i].se-1]!=-1) cnt-=2;
if (a[i].fi > a[i+1].fi) res=max(res, cnt);
// cout << cnt << ' ';
}
// en;
cout<<res;
}
Compilation message
count_triplets.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
55 | main()
| ^~~~
count_triplets.cpp: In function 'int main()':
count_triplets.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
57 | freopen("DUATHLON.INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
count_triplets.cpp:58:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | freopen("DUATHLON.OUT","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4444 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
4440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |