Submission #439008

#TimeUsernameProblemLanguageResultExecution timeMemory
439008skybergMountains (NOI20_mountains)C++17
77 / 100
2075 ms5908 KiB
#include <iostream> #include <vector> #include <cstring> #include <algorithm> using namespace std; long long int c[300000]; long long int mn[300000]; int t[100]; int main(){ int n; cin >> n; long long int ans = 0; if(n >= 10005){ cin >> c[0]; t[c[0]]++; mn[0] = 0; for(int i = 1; i < n; i++){ cin >> c[i]; for(int j = 0; j < c[i]; j++){ mn[i] += t[j]; } t[c[i]]++; } memset(t, 0, sizeof(t[0])* 100); t[c[n - 1]]++; for(int i = n - 2; i >= 0; i--){ long long int temp =0; for(int j = 0; j < c[i]; j++){ temp += t[j]; } ans += mn[i] * temp; t[c[i]]++; } cout << ans; } else{ for(int i = 0; i < n; i++){ cin >> c[i]; } for(int i = 1; i < n - 1; i++){ long long int a = 0, b = 0; for(int j = 0; j < i; j++){ if(c[j] < c[i])a++; } for(int j = i + 1; j < n; j++){ if(c[j] < c[i])b++; } ans += a * b; } cout << ans; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...