This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector <ll> unos;
int main() {
ll n, i, cont=0, a, b, j, uc=0, cc=0;
cin >> n;
ll xd[n], ceros[n];
bool lol=false, kk=false;
for(i=0;i<n;i++) {
cin >> xd[i];
if(xd[i-1]>xd[i]) lol=true;
if(xd[i]!=0 && xd[i]!=1) kk=true;
if(xd[i]==1) uc++, unos.push_back(i);
if(xd[i]==0) cc++;
ceros[i]=cc;
}
if(lol==false) {
cout << "0" << endl;
return 0;
}
if(kk==false) {
for(i=0;i<uc;i++) {
if(unos[i]!=0 && unos[i]!=n-1) {
cont+=ceros[unos[i]]*(cc-ceros[unos[i]]);
}
}
cout << cont << endl;
return 0;
}
for(i=1;i<n-1;i++) {
a=0;
b=0;
for(j=0;j<i;j++) {
if(xd[j]<xd[i]) a++;
}
for(j=i+1;j<n;j++) {
if(xd[j]<xd[i]) b++;
}
cont+=a*b;
}
cout << cont << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |