Submission #305556

#TimeUsernameProblemLanguageResultExecution timeMemory
305556nickmet2004Exercise Deadlines (CCO20_day1problem2)C++11
17 / 25
124 ms11892 KiB
#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n , d[N]; int F[N]; vector<int> E[N]; void upd(int i , int v){ for(; i <=n; i += i & -i) F[i]+=v; } int get(int i){ int sum = 0; for(; i; i -= i & -i) sum += F[i]; return sum; } int main (){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; ++i) cin >> d[i] ,E[d[i]].emplace_back(i); sort(d+ 1 , d + n + 1); for(int i=1; i<= n; ++i) if(d[i] < i){cout << -1; return 0;} for(int i = 1; i <= n; ++i) upd(i , 1); priority_queue<int> pq; int ans =0; for(int i = n; i; --i){ for(int x : E[i]) pq.push(x); int a= pq.top(); pq.pop(); upd(n - a + 1 ,-1); ans += get(n - a + 1); }cout << ans; }

Compilation message (stderr)

Main.cpp: In function 'int get(int)':
Main.cpp:14:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   14 |     for(; i; i -= i & -i) sum += F[i]; return sum;
      |     ^~~
Main.cpp:14:40: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   14 |     for(; i; i -= i & -i) sum += F[i]; return sum;
      |                                        ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...