Submission #307134

# Submission time Handle Problem Language Result Execution time Memory
307134 2020-09-27T07:28:26 Z Tamarpeikrishvili Exercise Deadlines (CCO20_day1problem2) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

int tree[200005]
long long ans = 0;
vector <int> v[200005];
priority_queue <int> pq;

int get(int idx){
        int sum = 0;
        while (idx > 0){
                sum += tree[idx];
                idx = idx - (idx & -idx);
        }
        return sum;
}

void upd(int idx ,int val, int MaxVal){
        while (idx <= MaxVal){
                tree[idx] += val;
                idx += (idx & -idx);
        }
}

int main (){
        int n;
        cin >> n;

        int a[n];
        for(int i=1; i<=n; i++) {
                cin >> a[i];
                
                v[a[i]].push_back(i);
        }

        sort(a+1, a+n+1); 

        for(int i=1; i<=n; i++){
                if(a[i] < i){
                        cout << -1 << endl;
                        return 0;
                }
        }
        for(int i=1; i<=n; i++) upd(i , 1, n);
        

        for(int i=n; i>0; i--){
                for(int j=0; j<v[i].size(); j++) {
                        pq.push(v[i][j]);
                }
                int k = pq.top(); 
                pq.pop();

                upd(n - k + 1, -1, n);
                ans = get(n - k + 1) + ans;
        }
        cout << ans;
 

}

Compilation message

Main.cpp:5:1: error: expected initializer before 'long'
    5 | long long ans = 0;
      | ^~~~
Main.cpp: In function 'int get(int)':
Main.cpp:12:24: error: 'tree' was not declared in this scope; did you mean 'free'?
   12 |                 sum += tree[idx];
      |                        ^~~~
      |                        free
Main.cpp: In function 'void upd(int, int, int)':
Main.cpp:20:17: error: 'tree' was not declared in this scope; did you mean 'free'?
   20 |                 tree[idx] += val;
      |                 ^~~~
      |                 free
Main.cpp: In function 'int main()':
Main.cpp:48:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |                 for(int j=0; j<v[i].size(); j++) {
      |                              ~^~~~~~~~~~~~
Main.cpp:55:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   55 |                 ans = get(n - k + 1) + ans;
      |                 ^~~
      |                 abs
Main.cpp:57:17: error: 'ans' was not declared in this scope; did you mean 'abs'?
   57 |         cout << ans;
      |                 ^~~
      |                 abs