Submission #1092388

# Submission time Handle Problem Language Result Execution time Memory
1092388 2024-09-24T01:20:56 Z huyy123 Mountains (NOI20_mountains) C++14
0 / 100
19 ms 5816 KB
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define rep2(i,a,b,c) for (int i=a;i<=b;i+=c)
#define rev(i,a,b) for (int i=a;i>=b;i--)
#define rev2(i,a,b,c) for (int i=a;i>=b;i-=c)
#define ii pair<int,int>
#define bit(i,j) ((i>>j)&1)
#define ull unsigned long long
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
const int N=1e5+5;
const int mod=1e9+7;
const int MAX=1e9;
int n,res,a[N],dp[N],s[N*4],dem[N];
vector<int> uni;
void update(int id,int l,int r,int i,int val)
{
    if(i>r||i<l)
        return;
    if(l==r)
    {
        s[id]=val;
        return;
    }
    int mid=(l+r)/2;
    update(id*2,l,mid,i,val);
    update(id*2+1,mid+1,r,i,val);
    s[id]=s[id*2]+s[id*2+1];
}
int get(int id,int l,int r,int u,int v)
{
    if(v<l||r<u)
        return 0;
    if(l>=u&&r<=v)
    {
        return s[id];
    }
    int mid=(l+r)/2;
    return get(id*2,l,mid,u,v)+get(id*2+1,mid+1,r,u,v);
}
void solution()
{
    cin>>n;
    rep(i,1,n)
    {
        cin>>a[i];
        uni.push_back(a[i]);
    }
    sort(uni.begin(),uni.end());
    uni.resize(unique(uni.begin(),uni.end())-uni.begin());
    rep(i,1,n) a[i]=lower_bound(uni.begin(),uni.end(),a[i])-uni.begin()+1;
    rep(i,1,n)
    {
        dp[i]=get(1,1,n,0,a[i]-1);
        update(1,1,n,a[i],1);
    }
    memset(s,0,sizeof(s));
    rev(i,n,1){
        res+=dp[i]*get(1,1,n,0,a[i]-1);
        update(1,1,n,a[i],1);
    }
    cout<<res;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if(fopen("Mountains.inp","r")){freopen("Mountains.inp","r",stdin);freopen("Mountains.out","w",stdout);}
    int test=1;
//    cin>>test;
    while(test--)
        solution();
}
/*

*/

Compilation message

Mountains.cpp: In function 'int32_t main()':
Mountains.cpp:72:43: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     if(fopen("Mountains.inp","r")){freopen("Mountains.inp","r",stdin);freopen("Mountains.out","w",stdout);}
      |                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:72:78: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |     if(fopen("Mountains.inp","r")){freopen("Mountains.inp","r",stdin);freopen("Mountains.out","w",stdout);}
      |                                                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3416 KB Output is correct
2 Runtime error 19 ms 5816 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 5444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 5444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 2 ms 3420 KB Output is correct
3 Correct 2 ms 3544 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Incorrect 2 ms 3420 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3420 KB Output is correct
2 Correct 2 ms 3420 KB Output is correct
3 Correct 2 ms 3544 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3420 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Incorrect 2 ms 3420 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 5444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3416 KB Output is correct
2 Runtime error 19 ms 5816 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -