답안 #1092390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092390 2024-09-24T01:24:08 Z huyy123 Mountains (NOI20_mountains) C++14
2 / 100
187 ms 22464 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=3e5+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);}
      |                                                                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Correct 174 ms 22336 KB Output is correct
3 Correct 187 ms 22464 KB Output is correct
4 Correct 182 ms 22464 KB Output is correct
5 Correct 174 ms 22336 KB Output is correct
6 Correct 176 ms 22336 KB Output is correct
7 Correct 177 ms 22348 KB Output is correct
8 Correct 178 ms 22460 KB Output is correct
9 Correct 165 ms 22392 KB Output is correct
10 Correct 176 ms 22464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 120 ms 17596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 120 ms 17596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 6 ms 9780 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Incorrect 4 ms 9820 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 6 ms 9780 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Incorrect 4 ms 9820 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 120 ms 17596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 9816 KB Output is correct
2 Correct 174 ms 22336 KB Output is correct
3 Correct 187 ms 22464 KB Output is correct
4 Correct 182 ms 22464 KB Output is correct
5 Correct 174 ms 22336 KB Output is correct
6 Correct 176 ms 22336 KB Output is correct
7 Correct 177 ms 22348 KB Output is correct
8 Correct 178 ms 22460 KB Output is correct
9 Correct 165 ms 22392 KB Output is correct
10 Correct 176 ms 22464 KB Output is correct
11 Incorrect 120 ms 17596 KB Output isn't correct
12 Halted 0 ms 0 KB -