Submission #65939365
Source Code Expand
//People who believe in miracles are as amazing as miracles themselves. #include<bits/stdc++.h> #define ll long long using namespace std; inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') f=-f;ch=getchar();} while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); return x*f; } const int N=3e5+10; int n,a[N]; ll ans; vector<int> vc,vc2; inline void solve(){ n=read(); for(int i=1;i<=n;++i) a[i]=read(); vc.emplace_back(1),vc2.emplace_back(1); for(int i=2;i<n;++i){ if(a[i]<a[i-1]&&a[i]<a[i+1]) vc.emplace_back(i); if(a[i]>a[i-1]&&a[i]>a[i+1]) vc2.emplace_back(i); } vc.emplace_back(n),vc2.emplace_back(n); for(int i=2;i<n;++i) if(a[i]>a[i-1]&&a[i]>a[i+1]){ int nxt=*lower_bound(vc.begin(),vc.end(),i); if(nxt<n){ int pre=*--lower_bound(vc.begin(),vc.end(),i); int nxtt=*upper_bound(vc2.begin(),vc2.end(),nxt); ans+=(ll)(i-pre)*(nxtt-nxt); } } printf("%lld\n",ans); } signed main(){ #ifndef ONLINE_JUDGE freopen("../1.in","r",stdin); freopen("../1.out","w",stdout); #endif return solve(),0; }
Submission Info
Submission Time | |
---|---|
Task | C - ~ |
User | include_BM |
Language | C++ 20 (gcc 12.2) |
Score | 350 |
Code Size | 1252 Byte |
Status | AC |
Exec Time | 30 ms |
Memory | 5860 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 350 / 350 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample00.txt, sample01.txt, sample02.txt |
All | sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample00.txt | AC | 1 ms | 3820 KiB |
sample01.txt | AC | 1 ms | 3772 KiB |
sample02.txt | AC | 1 ms | 3708 KiB |
testcase00.txt | AC | 5 ms | 4156 KiB |
testcase01.txt | AC | 21 ms | 5264 KiB |
testcase02.txt | AC | 4 ms | 3916 KiB |
testcase03.txt | AC | 22 ms | 5192 KiB |
testcase04.txt | AC | 18 ms | 4748 KiB |
testcase05.txt | AC | 21 ms | 5260 KiB |
testcase06.txt | AC | 15 ms | 4836 KiB |
testcase07.txt | AC | 21 ms | 5044 KiB |
testcase08.txt | AC | 1 ms | 3820 KiB |
testcase09.txt | AC | 1 ms | 3712 KiB |
testcase10.txt | AC | 9 ms | 4128 KiB |
testcase11.txt | AC | 30 ms | 5856 KiB |
testcase12.txt | AC | 21 ms | 4892 KiB |
testcase13.txt | AC | 30 ms | 5860 KiB |
testcase14.txt | AC | 8 ms | 5000 KiB |
testcase15.txt | AC | 5 ms | 4296 KiB |
testcase16.txt | AC | 8 ms | 4996 KiB |
testcase17.txt | AC | 4 ms | 4128 KiB |
testcase18.txt | AC | 8 ms | 4808 KiB |
testcase19.txt | AC | 3 ms | 4108 KiB |
testcase20.txt | AC | 8 ms | 5028 KiB |
testcase21.txt | AC | 4 ms | 4084 KiB |
testcase22.txt | AC | 8 ms | 4816 KiB |
testcase23.txt | AC | 5 ms | 4500 KiB |
testcase24.txt | AC | 8 ms | 4812 KiB |
testcase25.txt | AC | 4 ms | 4292 KiB |
testcase26.txt | AC | 8 ms | 4776 KiB |
testcase27.txt | AC | 3 ms | 3908 KiB |
testcase28.txt | AC | 8 ms | 4816 KiB |
testcase29.txt | AC | 4 ms | 4208 KiB |
testcase30.txt | AC | 8 ms | 4996 KiB |
testcase31.txt | AC | 2 ms | 3884 KiB |
testcase32.txt | AC | 8 ms | 4968 KiB |
testcase33.txt | AC | 4 ms | 4092 KiB |
testcase34.txt | AC | 8 ms | 5032 KiB |