提交时间:2022-10-15 11:29:09
运行 ID: 60385
#include <bits/stdc++.h> using namespace std; const int Max = 5e5 + 5 , Mod = 1e9 + 7; int a[ Max ]; int n , ans , sum; inline int Read() { int x = 0 , f = 1; char ch = getchar(); for( ; ch < '0' || ch > '9' ; ch = getchar() ) if( ch == '-' ) f = 0; for( ; ch >= '0' && ch <= '9' ; ch = getchar() ) x = ( x << 3 ) + ( x << 1 ) + ( ch ^ 48 ); return ( f ? x : -x ); } bool barrel[ 2005 ]; signed main() { n = Read(); if( n > 2000 ) exit( 0 ); for( int i = 1 ; i <= n ; i++ ) a[ i ] = Read(); for( int i = 1 ; i <= n ; i++ ) { memset( barrel , 0 , sizeof( barrel ) ); int cnt = 0; for( int j = i ; j <= n ; j++ ) { if( !barrel[ a[ j ] ] ) barrel[ a[ j ] ] = 1 , cnt = ( cnt + a[ j ] ) % Mod; ans += cnt; } } printf( "%d\n" , ans ); return 0; }