Submission #285689

#TimeUsernameProblemLanguageResultExecution timeMemory
285689NintsiChkhaidzeMountains (NOI20_mountains)C++14
100 / 100
513 ms16248 KiB
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); #define pb push_back #define f first #define s second #define ll long long #define int long long #define mod 1000000007 #define N 300005 using namespace std; int a[300005],fen[4][300005],X[300005]; pair<int,int> d[300005]; void upd(int x,int idx){ while (idx < N){ fen[x][idx]+=1; idx += (idx&(-idx)); } } int get(int x,int idx){ int sum=0; while (idx > 0){ sum += fen[x][idx]; idx -= (idx&(-idx)); } return sum; } main (){ int n; cin>>n; for (int i=1;i<=n;i++){ cin>>a[i]; d[i].f = a[i],d[i].s = i; } sort(d+1,d+n+1); int m=1; for (int i=1;i<=n;i++){ if (i > 1 && d[i - 1].f < d[i].f) m++; a[d[i].s] = m; } for (int i=1;i<=n;i++){ if (a[i] > 1) X[i] = get(1,a[i] - 1); upd(1,a[i]); } int ans=0; for (int i=n;i>=1;i--){ m=0; if (a[i] == 1) X[i]=0; else m = get(2,a[i - 1]),X[i] *= get(2,a[i] - 1); ans+=X[i]; upd(2,a[i]); } cout<<ans; }

Compilation message (stderr)

Mountains.cpp:27:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main (){
      |       ^
#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...