Submission #893336

#TimeUsernameProblemLanguageResultExecution timeMemory
8933361075508020060209tcExercise Deadlines (CCO20_day1problem2)C++14
25 / 25
89 ms26572 KiB
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #define int long long #define X first #define Y second int lowbit(int x){return x&-x;} int bit[500005]; void upd(int pl,int v){ while(pl<=500000){ bit[pl]+=v; pl+=lowbit(pl); } } int qsum(int pl){ int ret=0; while(pl){ ret=ret+bit[pl]; pl-=lowbit(pl); } return ret; } int n; int ar[500005]; vector<int>e[500005]; void init(){ cin>>n; for(int i=1;i<=n;i++){ cin>>ar[i]; ar[i]=min(ar[i],n); e[ar[i]].push_back(i); } } signed main(){ init(); int ans=0; priority_queue<int>pq; for(int i=n;i>=1;i--){ for(int j=0;j<e[i].size();j++){ pq.push(e[i][j]); } if(pq.size()==0){cout<<-1<<"\n";return 0;} ans+=i-pq.top()+qsum(pq.top()); upd(pq.top(),1); pq.pop(); } cout<<ans<<"\n"; }

Compilation message (stderr)

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