Submission #287121

# Submission time Handle Problem Language Result Execution time Memory
287121 2020-08-31T12:14:57 Z sabamaku Mountains (NOI20_mountains) C++14
0 / 100
2000 ms 2936 KB
#include<bits/stdc++.h>
using namespace std;

int n,x,p[3][200005],ans,d[200005],sum,sum1,s[200005];

map <long long,int> mp;

void update(int a){
    for(int i = a; i <= n; i += (i & -i)){
        p[x][i]++;
    }
}

void deleteit(int a){
    for(int i = a; i <= n; i += (i & -i)){
        p[1][i]--;
    }
}

void solve(int a){
    sum = 0;
    for(int i = a - 1; i >= 1; i -= (i & -i)){
        sum += p[x][i];
    }
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> d[i];
        s[i] = d[i];
    }
    sort(s + 1, s + n + 1);
    for(int i = 1; i <= n; i++){
        if(mp[s[i]] == 0){
            x++;
            mp[s[i]] = x; 
        }
    }
    x = 1;
    for(int i = n; i >= 2; i--){
        update(mp[d[i]]);
    }
    for(int i = 2; i < n; i++){
        deleteit(mp[d[i]]);
        x = 0;
        update(mp[d[i - 1]]);
        x = 1;
        solve(mp[d[i]]);
        sum1 = sum;
        x = 0;
        solve(mp[d[i]]);
        ans += sum * sum1;
        //cout << sum << " " << sum1 << " " << mp[d[i]] << endl;
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Execution timed out 2078 ms 1536 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 2936 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 2936 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 2936 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Execution timed out 2078 ms 1536 KB Time limit exceeded
3 Halted 0 ms 0 KB -