QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#346088#4895. Lovely DogszzafantiCompile Error//C++202.8kb2024-03-07 20:23:392024-03-07 20:23:40

Judging History

你现在查看的是最新测评结果

  • [2024-03-07 20:23:40]
  • 评测
  • [2024-03-07 20:23:39]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
using E=long long;
using lint=__int128;
constexpr lint inf=1e18+7;
constexpr double INF=log(inf);

int n,d;
vector<int> a,mu,w,primes,res;
vector<vector<int>> ver,divs,node;
bitset<200010> st;

E ksm(E a,E b){
  if(b*log(a)>=INF) return inf;
  E ret=1;
  while(b){
    if(b&1) ret=ret*a;
    a=a*a;
    b>>=1;
  }
  return ret;
}

vector<int> fa,hson,sz;
void dfs0(int u){
  sz[u]=1;
  for(auto p:ver[u]){
    if(p==fa[u]) continue;
    fa[p]=u;
    dfs0(p);
    sz[u]+=sz[p];
    if(sz[hson[u]]<sz[p]) hson[u]=p;
  }
}

vector<unordered_map<int,E>> sum;
void add0(int u,int x){
  for(auto p:divs[x]){
    sum[u][p]+=w[x];
  }
}

void add1(int u,int x){
  for(auto t:divs[x]){
    if(ksm(t,d+1)/x>n) continue;
    E tmp=ksm(t,d+1);
    tmp/=__gcd(tmp,(E)x);
    res[u]+=w[x]*mu[t]*sum[u][tmp];
  }
}

void dfs1(int u){
  if(sz[u]==1){
    node[u].emplace_back(u);
    add0(u,a[u]);
    add1(u,a[u]);
    return ;
  }
  dfs1(hson[u]);
  res[u]+=res[hson[u]];
  node[u].swap(node[hson[u]]);
  sum[u].swap(sum[hson[u]]);
  add0(u,a[u]);
  add1(u,a[u]);
  node[u].emplace_back(u);
  for(auto p:ver[u]){
    if(p==fa[u]||p==hson[u]) continue;
    dfs1(p);
    res[u]+=res[p];
    for(auto pt:node[p]){
      add1(u,a[pt]);
    }
    for(auto pt:node[p]){
      add0(u,a[pt]);
      node[u].emplace_back(pt);
    }
    unordered_map<int,E>().swap(sum[p]);
    vector<int>().swap(node[p]);
  }
}

int main(){

#ifdef zzafanti
  freopen("in.in","r",stdin);
#endif // zzafanti

  cin.tie(nullptr),cout.tie(nullptr)->sync_with_stdio(false);

  cin>>n>>d;
  ver.resize(n+1); divs.resize(n+1); node.resize(n+1); a.resize(n+1); res.resize(n+1);
  for(int i=1; i<n; i++){
    int x,y;
    cin>>x>>y;
    ver[x].emplace_back(y);
    ver[y].emplace_back(x);
  }
  for(int i=1; i<=n; i++) cin>>a[i];

  mu=w=vector<int>(n+1);
  mu[1]=1;
  for(int i=2; i<=n; i++){
    if(!st[i]){
      primes.emplace_back(i);
      mu[i]=-1;
    }
    for(auto j:primes){
      if(i*j>n) break;
      st[i*j]=1;
      if(i%j==0){
        mu[i*j]=0;
        break;
      }
      mu[i*j]=mu[i]*mu[j];
    }
  }
  for(int i=1; i<=n; i++){
    int x=i; w[i]=1;
    for(int j=2; j*j<=x; j++){
      if(x%j) continue;
      int s=0;
      while(x%j==0) x/=j,s++,w[i]=-w[i];
      if(s>d){
        w[i]=0;
        break;
      }
    }
    if(x>1) w[i]*=-1;
    //cerr<<i<<' '<<w[i]<<' '<<mu[i]<<endl;
  }

  for(int i=1; i<=n; i++){
    for(int j=i; j<=n; j+=i){
      divs[j].emplace_back(i);
    }
  }

  sum.resize(n+1),hson.resize(n+1),sz.resize(n+1),fa.resize(n+1);
  dfs0(1);
  dfs1(1);

  for(int i=1; i<=n; i++){
    cout<<res[i]<<'\n';
  }

  return 0;
}

詳細信息

answer.code:7:25: error: call of overloaded ‘log(const lint&)’ is ambiguous
    7 | constexpr double INF=log(inf);
      |                      ~~~^~~~~
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/c++config.h:679,
                 from /usr/include/c++/13/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:33,
                 from answer.code:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:104:1: note: candidate: ‘double log(double)’
  104 | __MATHCALL_VEC (log,, (_Mdouble_ __x));
      | ^~~~~~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:114:
/usr/include/c++/13/cmath:326:3: note: candidate: ‘constexpr long double std::log(long double)’
  326 |   log(long double __x)
      |   ^~~
/usr/include/c++/13/cmath:322:3: note: candidate: ‘constexpr float std::log(float)’
  322 |   log(float __x)
      |   ^~~