Submission #308999

#TimeUsernameProblemLanguageResultExecution timeMemory
308999giorgigagua2006Exercise Deadlines (CCO20_day1problem2)C++17
17 / 25
178 ms22904 KiB
#include<bits/stdc++.h> using namespace std; long long f[12312],N=12312,p,k; priority_queue<long long>q; void upd(int i, int value) { while(i<N) { f[i]+=value; i+=(i & -i); } } int sum(int i) { int s=0; while(i) { s+=f[i]; i-=(i & -i); } return s; } long long i,j,mx,ans,n; long long d[223123]; vector<long long>v[213213]; int main() { cin>>n; for(i=1;i<=n;i++) { cin>>d[i]; v[d[i]].push_back(i); } for(int i = 1; i <= n; ++i) upd(i , 1); for(i=n;i>0;i--) { for(j=0;j<v[i].size();j++) q.push(v[i][j]); if(q.size()==0) { cout<<-1; return 0; } mx=q.top(); q.pop(); upd(n-mx+1,-1); ans+=sum(n-mx+1); } cout<<ans; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:40:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int, std::allocator<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for(j=0;j<v[i].size();j++)
      |           ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...