Submission #7399913


Source Code Expand

Copy
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define MAXN 100101
#define LL long long
using namespace std;
int n;
int a[MAXN],loc[MAXN],l[MAXN],r[MAXN],ls[MAXN],rs[MAXN];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        l[i]=i-1;
        r[i]=i+1;
        loc[a[i]]=i;
    }
    LL ans=0;
    for(int i=1;i<n;i++)
    {
        int tx=loc[i],L=l[tx],R=r[tx];
        ans+=((L?(ls[L]+1)*(LL)(rs[tx]+1):0)+(R<=n?(ls[tx]+1)*(LL)(rs[R]+1):0))*(LL)i;
        rs[L]=ls[R]=R-L-1;l[R]=L;r[L]=R;
     
    }
    cout<<ans<<endl;
    
    return 0;
}

Submission Info

Submission Time
Task E - Second Sum
User George_Plover
Language C++ (GCC 5.4.1)
Score 500
Code Size 656 Byte
Status AC
Exec Time 13 ms
Memory 2560 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:12:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:15:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 22
Set Name Test Cases
Sample 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-small-01.txt, 01-small-02.txt, 01-small-03.txt, 01-small-04.txt, 01-small-05.txt, 02-large-01.txt, 02-large-02.txt, 02-large-03.txt, 02-large-04.txt, 02-large-05.txt, 03-max-01.txt, 03-max-02.txt, 04-min-01.txt, 05-sorted-01.txt, 05-sorted-02.txt, 06-almost-sorted-01.txt, 06-almost-sorted-02.txt, 06-almost-sorted-03.txt, 06-almost-sorted-04.txt
Case Name Status Exec Time Memory
00-sample-01.txt AC 1 ms 256 KB
00-sample-02.txt AC 1 ms 256 KB
00-sample-03.txt AC 1 ms 256 KB
01-small-01.txt AC 1 ms 256 KB
01-small-02.txt AC 1 ms 256 KB
01-small-03.txt AC 1 ms 256 KB
01-small-04.txt AC 1 ms 256 KB
01-small-05.txt AC 1 ms 256 KB
02-large-01.txt AC 12 ms 2304 KB
02-large-02.txt AC 8 ms 1536 KB
02-large-03.txt AC 12 ms 2432 KB
02-large-04.txt AC 13 ms 2432 KB
02-large-05.txt AC 8 ms 1664 KB
03-max-01.txt AC 13 ms 2560 KB
03-max-02.txt AC 13 ms 2560 KB
04-min-01.txt AC 1 ms 256 KB
05-sorted-01.txt AC 11 ms 2176 KB
05-sorted-02.txt AC 12 ms 2176 KB
06-almost-sorted-01.txt AC 11 ms 2048 KB
06-almost-sorted-02.txt AC 12 ms 2048 KB
06-almost-sorted-03.txt AC 12 ms 2176 KB
06-almost-sorted-04.txt AC 11 ms 2048 KB