Submission #1092155

#TimeUsernameProblemLanguageResultExecution timeMemory
1092155khanhgngMountains (NOI20_mountains)C++17
2 / 100
38 ms5832 KiB
#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 (stderr)

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);}
      |                                                             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...