Submission #25785

#TimeUsernameProblemLanguageResultExecution timeMemory
25785kajebiii즐거운 채소 기르기 (JOI14_growing)C++14
30 / 100
23 ms10568 KiB
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++) #define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++) #define SZ(v) ((int)(v).size()) #define ALL(v) (v).begin(),(v).end() #define one first #define two second typedef long long ll; typedef pair<int, int> pi; const int INF = 0x3f2f1f0f; const ll LINF = 1ll * INF * INF; const int MAX_N = 3e5 + 100; struct BIT { int val[MAX_N]; BIT() { for(int i=0; i<MAX_N; i++) val[i] = 0; } void update(int v, int k) { for(v++; v<MAX_N; v+=v&-v) val[v] += k; } int getSum(int v) { int res = 0; for(v++; v; v-=v&-v) res += val[v]; return res; } int getSum(int a, int b) { return getSum(b) - getSum(a-1); } }; int N, Nr[MAX_N]; ll CntL[MAX_N], CntR[MAX_N]; vector<int> Co; int main() { cin >> N; REPO(i, N) scanf("%d", &Nr[i]), Co.push_back(Nr[i]); sort(ALL(Co)); Co.erase(unique(ALL(Co)), Co.end()); int cN = SZ(Co); for(int i=1; i<=N; i++) Nr[i] = lower_bound(ALL(Co), Nr[i]) - Co.begin(); BIT bitL, bitR; for(int i=1; i<=N; i++) { CntL[i] = CntL[i-1] + bitL.getSum(Nr[i]+1, cN-1); bitL.update(Nr[i], 1); } for(int i=N; i>=1; i--) { CntR[i] = CntR[i+1] + bitR.getSum(Nr[i]+1, cN-1); bitR.update(Nr[i], 1); } ll ans = LINF; for(int i=0; i<=N; i++) ans = min(ans, CntL[i] + CntR[i+1]); printf("%lld\n", ans); return 0; }

Compilation message (stderr)

growing.cpp: In function 'int main()':
growing.cpp:39:63: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  cin >> N; REPO(i, N) scanf("%d", &Nr[i]), Co.push_back(Nr[i]);
                                                               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...