제출 #380253

#제출 시각아이디문제언어결과실행 시간메모리
380253vishesh312Vudu (COCI15_vudu)C++17
126 / 140
772 ms65540 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using ordered_set = tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>; #define all(x) begin(x), end(x) #define sz(x) (int)x.size() const int mod = 1e9+7; void solve(int tc) { int n; cin >> n; array<ll, 2> v[n+1]; v[0][0] = 0; v[0][1] = 0; for (int i = 1; i <= n; ++i) { cin >> v[i][0]; v[i][1] = i; } int a[n+1]; ll p; cin >> p; for (int i = 1; i <= n; ++i) { v[i][0] += v[i-1][0] - p; } sort(v, v+n+1); ll cur = 0; for (int i = 0; i <= n; ++i) { if (i) if (v[i][0] == v[i-1][0]) --cur; a[v[i][1]] = cur; ++cur; } ll ans = 0; ordered_set s; s.insert(a[0]-1); for (int i = 1; i <= n; ++i) { ans += s.order_of_key(a[i]); s.insert(a[i]-1); } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc = 1; //cin >> tc; for (int i = 1; i <= tc; ++i) solve(i); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...