Submission #715393

# Submission time Handle Problem Language Result Execution time Memory
715393 2023-03-26T15:25:13 Z fuad27 Sirni (COCI17_sirni) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std;
struct DSU {
  vector<int> e;
  DSU(int N) {e = vector<int>(N, -1);}
  int get(int x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
  bool same_set(int a, int b) { return get(a) == get(b); }
  int size(int x) { return -e[get(x)]; }
  bool unite(int x, int y) {
    x = get(x), y = get(y);
    if (x == y) return false;
    if (e[x] > e[y]) swap(x, y);
    e[x] += e[y]; e[y] = x; return true;
  }
};
const int N=1e7+10;
int great[N];
vector<pair<int,int>> ed[N];
vector<int> v;
int main () {
  cin.tie(0)->sync_with_stdio(0);
  for(int i = 0;i<N;i++)great[i]=1e9;
  int n;
  cin >> n;
  {
    set<int> s;
    for(int i = 0;i<n;i++) {
      int a;
      cin >> a;
      s.insert(a);
    }
    v=vector<int>(s.begin(),s.end());
  }
  n=v.size();
  for(int i = 0;i<n;i++)great[v[i]]=i;
  for(int j = N-3;j>=0;j--) {
      great[j]=min(great[j],great[j+1]);
  }
  for(int i=0;i<n;i++) {
    for(int j=v[i];j<N-3;j+=v[i]) {
      if(j!=v[i]) {
        if(great[j]<n) {
          ed[v[great[j]]-j].push_back({i,great[j]});
        }
      }
      else if(great[j+1]<n) {
        ed[v[great[j+1]]-j].push_back({i,great[j+1]});
      }
    }
  }
  sort(ed.begin(),ed.end());
  DSU d(2*n+1);
  long long sum=0;
  for(int i = 0;i<N-3;i++) {
    for(auto j:ed[i]) {
      sum+=(int)d.unite(j.second,j.first)*i;
    }
  }
  cout << sum << "\n";
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:53:11: error: request for member 'begin' in 'ed', which is of non-class type 'std::vector<std::pair<int, int> > [10000010]'
   53 |   sort(ed.begin(),ed.end());
      |           ^~~~~
sirni.cpp:53:22: error: request for member 'end' in 'ed', which is of non-class type 'std::vector<std::pair<int, int> > [10000010]'
   53 |   sort(ed.begin(),ed.end());
      |                      ^~~