Submission #57756106
Source Code Expand
/*
Author : Hocky Yudhiono
Saturday, September 14, 2024 PM08:17:24
*/
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> PII;
typedef pair<int, int> pii;
typedef pair<LL, LL> PLL;
typedef pair<LL, LL> pll;
typedef long double ld;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define popf pop_front
#define pf push_front
#define popb pop_back
#define pb push_back
#define fi first
#define se second
const double EPS = 1e-9;
const int INFMEM = 63;
// Do dir^1 to get reverse direction
const int dx[8] = {0,0,1,-1,1,-1,1,-1};
const int dy[8] = {1,-1,0,0,1,-1,-1,1};
const char dch[4] = {'R','L','D','U'};
// Do (dir + 2)%4 to get reverse direction
// const int dx[8] = {-1,0,1,0,-1,1,1,-1};
// const int dy[8] = {0,1,0,-1,1,1,-1,-1};
// const char dch[4] = {'U','R','D','L'};
const double PI = 3.141592653589793;
inline void fasterios(){
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
}
#define endl '\n'
const int MOD = 1000000007;
// const int MOD = 998244353;
const int kMax = 2e5;
vector <LL> bucket[kMax + 5];
LL isi[kMax + 5];
int main(){
fasterios();
int n; cin >> n;
LL ans = 0;
rep(i,1,n + 1) {
cin >> isi[i];
bucket[isi[i]].pb(i);
if(bucket[isi[i]].size() == 1) {
// The first one
ans += n - i + 1;
}
}
for(int i = 0;i <= n+1;i++){
reverse(all(bucket[i]));
}
LL curans = 0;
for(int i = 1;i <= n;i++){
curans += ans;
// Buang
ans -= (n - i + 1);
bucket[isi[i]].pop_back();
if(bucket[isi[i]].size()) {
ans += (n - bucket[isi[i]].back() + 1);
}
}
cout << curans << endl;
}
Submission Info
Submission Time |
|
Task |
E - I Hate Sigma Problems |
User |
hocky |
Language |
C++ 20 (gcc 12.2) |
Score |
475 |
Code Size |
1904 Byte |
Status |
AC |
Exec Time |
34 ms |
Memory |
16072 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
475 / 475 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_sample_01.txt, 00_sample_02.txt |
All |
00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt |
Case Name |
Status |
Exec Time |
Memory |
00_sample_01.txt |
AC |
2 ms |
3504 KiB |
00_sample_02.txt |
AC |
2 ms |
3568 KiB |
01_test_01.txt |
AC |
33 ms |
13916 KiB |
01_test_02.txt |
AC |
31 ms |
14036 KiB |
01_test_03.txt |
AC |
34 ms |
13968 KiB |
01_test_04.txt |
AC |
30 ms |
13880 KiB |
01_test_05.txt |
AC |
31 ms |
13952 KiB |
01_test_06.txt |
AC |
31 ms |
13912 KiB |
01_test_07.txt |
AC |
32 ms |
14040 KiB |
01_test_08.txt |
AC |
32 ms |
13904 KiB |
01_test_09.txt |
AC |
30 ms |
13968 KiB |
01_test_10.txt |
AC |
32 ms |
14036 KiB |
01_test_11.txt |
AC |
24 ms |
9880 KiB |
01_test_12.txt |
AC |
24 ms |
9776 KiB |
01_test_13.txt |
AC |
25 ms |
9308 KiB |
01_test_14.txt |
AC |
24 ms |
9884 KiB |
01_test_15.txt |
AC |
27 ms |
10860 KiB |
01_test_16.txt |
AC |
17 ms |
10532 KiB |
01_test_17.txt |
AC |
16 ms |
10508 KiB |
01_test_18.txt |
AC |
7 ms |
5988 KiB |
01_test_19.txt |
AC |
5 ms |
5036 KiB |
01_test_20.txt |
AC |
27 ms |
12608 KiB |
01_test_21.txt |
AC |
10 ms |
6420 KiB |
01_test_22.txt |
AC |
2 ms |
3376 KiB |
01_test_23.txt |
AC |
2 ms |
3492 KiB |
01_test_24.txt |
AC |
2 ms |
3404 KiB |
01_test_25.txt |
AC |
20 ms |
16072 KiB |