답안 #1092155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092155 2024-09-23T10:58:36 Z khanhgng Mountains (NOI20_mountains) C++17
2 / 100
38 ms 5832 KB
#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define ld long double
#define pii pair<int,int>
#define SZ(x) ((int)(x.size()))
#define bit(i,x) ((x>>i)&1)
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define task "mountains"

using namespace std;

mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll l,ll r){assert(l<=r);return uniform_int_distribution<ll>(l,r)(rd);}

const int MAXn=5e5+7;
const int MOD=1e9+7;
const ll oo = 1e18;
const ll BASE=3137LL;

int n,a[MAXn],dp[MAXn],res;

struct FenwickTree{
    int f[MAXn];
    int N;
    void init(int n){FOR(i,1,n)f[i]=0;N=n;}
    void upd(int idx,int val){
        for(idx;idx<=N;idx+=(idx&-idx)){
            f[idx]+=val;
        }
    }
    int get(int idx){
        int ans=0;
        for(idx;idx>=1;idx-=(idx&-idx)){
            ans+=f[idx];
        }
        return ans;
    }
}ft;

void solution(){
    cin>>n;
    vector<int>zip;
    FOR(i,1,n)cin>>a[i],zip.pb(a[i]);
    sort(zip.begin(),zip.end());
    zip.resize(unique(zip.begin(),zip.end())-zip.begin());
    FOR(i,1,n)a[i]=lower_bound(zip.begin(),zip.end(),a[i])-zip.begin()+1;
    ft.init(n);
    FOR(i,1,n){
        dp[i]=ft.get(a[i]-1);
        ft.upd(a[i],1);
    }
    ft.init(n);
    FORD(i,n,1){
        res+=dp[i]*ft.get(a[i]-1);
        ft.upd(a[i],1);
    }
    cout<<res;

}

int32_t main(){
    if(fopen(task".inp","r")){freopen(task".inp","r",stdin);freopen(task".out","w",stdout);}
    ios_base::sync_with_stdio(0);cin.tie(0);
    int ntest=1;//cin>>ntest;
    while(ntest--){solution();}
    cerr<<"\n"<<1.0*clock()/CLOCKS_PER_SEC<<"s ";
}

Compilation message

Mountains.cpp: In member function 'void FenwickTree::upd(int, int)':
Mountains.cpp:32:13: warning: statement has no effect [-Wunused-value]
   32 |         for(idx;idx<=N;idx+=(idx&-idx)){
      |             ^~~
Mountains.cpp: In member function 'int FenwickTree::get(int)':
Mountains.cpp:38:13: warning: statement has no effect [-Wunused-value]
   38 |         for(idx;idx>=1;idx-=(idx&-idx)){
      |             ^~~
Mountains.cpp: In function 'int32_t main()':
Mountains.cpp:67:38: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     if(fopen(task".inp","r")){freopen(task".inp","r",stdin);freopen(task".out","w",stdout);}
      |                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:67:68: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |     if(fopen(task".inp","r")){freopen(task".inp","r",stdin);freopen(task".out","w",stdout);}
      |                                                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 26 ms 5332 KB Output is correct
3 Correct 25 ms 5252 KB Output is correct
4 Correct 27 ms 5332 KB Output is correct
5 Correct 27 ms 5068 KB Output is correct
6 Correct 29 ms 5332 KB Output is correct
7 Correct 25 ms 5328 KB Output is correct
8 Correct 27 ms 5328 KB Output is correct
9 Correct 27 ms 5332 KB Output is correct
10 Correct 27 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 5832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 5832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 5832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 26 ms 5332 KB Output is correct
3 Correct 25 ms 5252 KB Output is correct
4 Correct 27 ms 5332 KB Output is correct
5 Correct 27 ms 5068 KB Output is correct
6 Correct 29 ms 5332 KB Output is correct
7 Correct 25 ms 5328 KB Output is correct
8 Correct 27 ms 5328 KB Output is correct
9 Correct 27 ms 5332 KB Output is correct
10 Correct 27 ms 5076 KB Output is correct
11 Incorrect 38 ms 5832 KB Output isn't correct
12 Halted 0 ms 0 KB -