Submission #996800

#TimeUsernameProblemLanguageResultExecution timeMemory
996800cpptowinMountains (NOI20_mountains)C++17
100 / 100
132 ms34496 KiB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(),x.end()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
struct BIT
{
    int t[maxn];
    void up(int x,int val)
    {
        for( ; x < maxn ; x += lb(x)) t[x] += val;
    }
    int get(int x)
    {
        int ans = 0;
        for( ; x ; x -= lb(x)) ans += t[x];
        return ans;
    }
}t1,t2;
int n,a[maxn];
vi nen;
int p[maxn],s[maxn];
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    fo(i,1,n) 
    {
        cin >> a[i];
        nen.pb(a[i]);
    }
    sort(all(nen));
    nen.erase(unique(all(nen)),nen.end());
    fo(i,1,n)
    {
        a[i] = lower_bound(all(nen),a[i]) - nen.begin() + 1;
        p[i] = t1.get(a[i] - 1);
        t1.up(a[i],1);
    }
    fod(i,n,1)
    {
        s[i] = t2.get(a[i] - 1);
        t2.up(a[i],1);
    }
    int ans = 0;
    fo(i,1,n) ans += s[i] * p[i];
    cout << ans;
}

Compilation message (stderr)

Mountains.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main()
      | ^~~~
Mountains.cpp: In function 'int main()':
Mountains.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(name ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...