# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
87415 | 2018-11-30T18:46:06 Z | nikolapesic2802 | Vudu (COCI15_vudu) | C++14 | 393 ms | 36248 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ll long long #define pb push_back #define sz(x) (int)(x).size() #define mp make_pair #define f first #define s second #define all(x) x.begin(), x.end() using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key() template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; } template<class T> ostream& operator<<(ostream& os, const vector<T>& a) { os << '{'; for(int i=0;i<sz(a);i++) { if(i>0&&i<sz(a)-1) os << ", "; os << a[i]; } os << '}'; return os; } const int N=1e6+5; vector<ll> pre(N); vector<int> fen(N),mapa(N); void update(int i){ for(;i<N;i+=i&(-i)) fen[i]++; } int get(int i){ int sum=0; for(;i;i-=i&(-i)) sum+=fen[i]; return sum; } int main() { int n,p; scanf("%i",&n); for(int i=1;i<=n;i++) scanf("%lld",&pre[i]); scanf("%i",&p); vector<pair<ll,int> > poz; for(int i=1;i<=n;i++) { pre[i]+=pre[i-1]-p; poz.pb({pre[i],i}); } poz.pb({0,0}); sort(poz.begin(),poz.end()); for(int i=0;i<=n;i++) mapa[poz[i].second]=i+1; ll ans=0; update(mapa[0]); for(int i=1;i<=n;i++) { ans+=get(mapa[i]); update(mapa[i]); } printf("%lld\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 16248 KB | Output is correct |
2 | Correct | 19 ms | 16276 KB | Output is correct |
3 | Correct | 21 ms | 16348 KB | Output is correct |
4 | Correct | 387 ms | 36196 KB | Output is correct |
5 | Correct | 222 ms | 36204 KB | Output is correct |
6 | Correct | 341 ms | 36220 KB | Output is correct |
7 | Correct | 393 ms | 36220 KB | Output is correct |
8 | Correct | 303 ms | 36220 KB | Output is correct |
9 | Correct | 377 ms | 36248 KB | Output is correct |
10 | Correct | 332 ms | 36248 KB | Output is correct |