結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー eQeeQe
提出日時 2021-11-06 19:26:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,305 bytes
コンパイル時間 4,481 ms
コンパイル使用メモリ 239,688 KB
実行使用メモリ 39,040 KB
最終ジャッジ日時 2024-04-25 08:00:33
合計ジャッジ時間 11,849 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In member function 'std::vector<std::pair<long long int, long long int> > PrimeFact::get(ll)':
main.cpp:64:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   64 |     for(auto [p,a]:m)res.push_back({p,a});
      |              ^

ソースコード

diff #

#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
template<class T1, class T2>istream& operator >> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template<class T1, class T2>ostream& operator << (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os;}
template<class T>istream& operator >> (istream& is, vector<T>& v) { for(T& x:v) is >> x; return is; }
template<class T>ostream& operator << (ostream& os, const vector<T>& v) {for(int i=0;i<v.size();i++) {os << v[i] << (i+1 == v.size() ? "":" ");} return os;}

//istream& operator >> (istream& is, modint1000000007& x) { unsigned int t; is >> t; x=t; return is; }
//istream& operator >> (istream& is, modint998244353& x) { unsigned int t; is >> t; x=t; return is; }
ostream& operator << (ostream& os, const modint1000000007& x) { os << x.val(); return os; }
ostream& operator << (ostream& os, const modint998244353& x) { os << x.val(); return os; }
template<class... A> void pt()      { std::cout << "\n"; }
template<class... A> void pt_rest() { std::cout << "\n"; }
template<class T, class... A> void pt_rest(const T& first, const A&... rest) { std::cout << " " << first; pt_rest(rest...); }
template<class T, class... A> void pt(const T& first, const A&... rest)      { std::cout << first; pt_rest(rest...); }

static const ll INF=1e18+7;
static const double PI=acos(-1);
static const double EPS=1e-10;

using v1d=vector<ll>;
using v2d=vector<v1d>;
using v3d=vector<v2d>;
using v4d=vector<v3d>;

using S=ll;
S op(S a,S b){
  return max(a,b);
}
S e(){
  return 0;
}

struct PrimeFact{
  v1d spf;
  PrimeFact(ll N){init(N);}
  void init(ll N){//前処理.spfを求める
    spf.assign(N+1,0);
    for (ll i=0;i<= N;i++)spf[i]=i;
    for (ll i=2;i*i<=N;i++){
      if (spf[i]!=i)continue;
      
      for (ll j=i+i;j<=N;j+=i){
        spf[j]=i;
      }
    }
  }
  vector<pll>get(ll n){//nの素因数分解を求める
    vector<pll>res;
    map<ll,ll> m;
    while (n!=1) {
      m[spf[n]]++;
      n/=spf[n];
    }
    for(auto [p,a]:m)res.push_back({p,a});
    return res;
  }
};


int main(void) {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  
  ll N;cin>>N;
  v1d a(N);cin>>a;
  ll MAX=1e6+7;
  vector<pll>cnt(MAX);
  for(ll i=0;i<MAX;i++)cnt[i]={0,i};
  
  PrimeFact pf(MAX);
  for(ll i=0;i<N;i++){
    auto prim=pf.get(a[i]);
    map<ll,ll>mem;
    function<void(vector<pll>)>dfs=[&](vector<pll> v){
      ll t=1;
      for(ll i=0;i<v.size();i++)t*=pow(v[i].first,v[i].second);
      if(mem.count(t))return;
      cnt[t].first++;
      for(ll i=0;i<v.size();i++){
        v[i].second--;
        if(v[i].second>=0)dfs(v);
        v[i].second++;
      }
      mem[t]=1;
    };
    
    dfs(prim);
    
  }
  sort(all(cnt));
  
  segtree<S,op,e>seg(MAX);
  for(ll i=0;i<MAX;i++)seg.set(i,cnt[i].second);
  
  for(ll k=0;k<N;k++){
    ll p=lower_bound(all(cnt),make_pair(N-k,-INF))-cnt.begin();
    pt(seg.prod(p,MAX));
  }
  
}


0