Submission #25798

#TimeUsernameProblemLanguageResultExecution timeMemory
25798kdh9949즐거운 채소 기르기 (JOI14_growing)C++14
100 / 100
153 ms5536 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct Dat{ int x, i; bool operator<(const Dat &oth) const { return x < oth.x; } }; int n; Dat a[300010]; ll ans; struct BIT{ int dat[300010]; void upd(int x, int v){ for(; x <= n; x += x & -x) dat[x] += v; } int get(int x){ int ret = 0; for(; x; x -= x & -x) ret += dat[x]; return ret; } int get(int s, int e){ return get(e) - get(s - 1); } } B; int main(){ scanf("%d", &n); for(int i = 1, x; i <= n; i++){ scanf("%d", &x); B.upd(i, 1); a[i] = {x, i}; } sort(a + 1, a + n + 1); for(int i = 1, j; i <= n; i = j){ for(j = i; j <= n && a[j].x == a[i].x; j++){ B.upd(a[j].i, -1); } for(int k = i; k < j; k++){ ans += min(B.get(1, a[k].i), B.get(a[k].i, n)); } } printf("%lld\n", ans); }

Compilation message (stderr)

growing.cpp: In function 'int main()':
growing.cpp:24:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
growing.cpp:26:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &x);
                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...