Submission #40837

#TimeUsernameProblemLanguageResultExecution timeMemory
40837HassoonyVudu (COCI15_vudu)C++14
70 / 140
1079 ms65536 KiB
#include<bits/stdc++.h> #include<unordered_map> using namespace std; typedef long long ll; typedef double D; const ll inf=(1ll<<61); const int mod=1e9+7; const int MX=1e6+9; int n,bit[MX]; int a[MX]; ll p; unordered_map<ll,int>has; vector<ll>hashy; void add(int x){ while(x<MX){ bit[x]++; x+=x&-x; } } int get(int x){ int ret=0; while(x){ ret+=bit[x]; x-=x&-x; } return ret; } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } ll sum=0; scanf("%lld",&p); for(int i=1;i<=n;i++){ sum+=a[i]; sum-=p; hashy.push_back(sum); } hashy.push_back(0); sort(hashy.begin(),hashy.end()); int tt=0; for(auto pp:hashy){ if(has[pp]==0)has[pp]=++tt; } add(has[0]); ll ans=0; int x; sum=0; for(int i=1;i<=n;i++){ sum+=a[i]; sum-=p; x=has[sum]; ans+=get(x); add(x); } // cout<<endl; cout<<ans<<endl; }

Compilation message (stderr)

vudu.cpp: In function 'int main()':
vudu.cpp:29:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
vudu.cpp:31:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^
vudu.cpp:34:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&p);
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...