题目传送门:https://agc003.contest.atcoder.jp/tasks/agc003_d

题目大意:

给定\(n\)个数\(s_i\),要求从中选出尽可能多的数,满足任意两个数之积都不是完全立方数


对于每个数\(s_i\),有\(s_i=\prod\limits_{i=1}^mp_i^{k_i}\),则我们令\(a_i=\prod\limits_{i=1}^mp_i^{k_i\%3}\),然后我们用\(a_i\)代替\(s_i\)来进行考虑,

对于每个\(a_i\),满足\(a_i×a_j\)为立方数的\(a_j\)只有一种取值,我们可以贪心地选择出现次数较多的那一种

预处理出\(\sqrt[3]{S}\)内的质数,对于每个\(s_i\)可以在\(O(M+\log s_i)\)的时间内求出\(a_i\)

然后对于考虑每个质因子的次数,可以求出\(a_j\)

(其实这题时限够大,可以预处理质数)

/*program from Wolfycz*/
#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Fi first
#define Se second
#define inf 0x7f7f7f7f
#define sqr(x) ((x)*(x))
#define cub(x) ((x)*(x)*(x))
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int frd(){
int x=0,f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline int read(){
int x=0,f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0) putchar('-'),x=-x;
if (x>9) print(x/10);
putchar(x%10+'0');
}
const int N=1e5;
ll A[N+10],B[N+10];
map<ll,int>Mp;
int main(){
int n=read();
for (int i=1;i<=n;i++){
ll x,y=1;
scanf("%lld",&x);
for (ll j=2;cub(j)<=x;j++) while (x%cub(j)==0) x/=cub(j);
map<ll,int>::iterator it=Mp.find(x);
if (it==Mp.end()) Mp.insert(map<ll,int>::value_type(x,1));
else it->Se++;
A[i]=x;
for (ll j=2;cub(j)<=x;j++){
if (x%j==0){
y*=(x%sqr(j)==0)?j:sqr(j);
while (x%j==0) x/=j;
}
}
y*=(sqr((ll)sqrt(x))==x)?(ll)sqrt(x):sqr(x);
B[i]=y;
}
int Ans=0;
map<ll,int>::iterator it=Mp.find(1);
if (it!=Mp.end()) Ans++,it->Se=0;
for (int i=1;i<=n;i++){
int res=0;
map<ll,int>::iterator x=Mp.find(A[i]);
map<ll,int>::iterator y=Mp.find(B[i]);
if (x!=Mp.end()) res=max(res,x->Se),x->Se=0;
if (y!=Mp.end()) res=max(res,y->Se),y->Se=0;
Ans+=res;
}
printf("%d\n",Ans);
return 0;
}

AtCoder Grand Contest 003 D - Anticube的更多相关文章

  1. AtCoder Grand Contest 003

    AtCoder Grand Contest 003 A - Wanna go back home 翻译 告诉你一个人每天向哪个方向走,你可以自定义他每天走的距离,问它能否在最后一天结束之后回到起点. ...

  2. AtCoder Grand Contest 003 E - Sequential operations on Sequence

    题目传送门:https://agc003.contest.atcoder.jp/tasks/agc003_e 题目大意 一串数,初始为\(1\sim N\),现有\(Q\)个操作,每次操作会把数组长度 ...

  3. AtCoder Grand Contest 003 F - Fraction of Fractal

    题目传送门:https://agc003.contest.atcoder.jp/tasks/agc003_f 题目大意: 给定一个\(H×W\)的黑白网格,保证黑格四连通且至少有一个黑格 定义分形如下 ...

  4. Atcoder Grand Contest 003 F - Fraction of Fractal(矩阵乘法)

    Atcoder 题面传送门 & 洛谷题面传送门 Yet another AGC F,然鹅这次就没能自己想出来了-- 首先需注意到题目中有一个条件叫做"黑格子组成的连通块是四联通的&q ...

  5. [Atcoder Grand Contest 003] Tutorial

    Link: AGC003 传送门 A: 判断如果一个方向有,其相反方向有没有即可 #include <bits/stdc++.h> using namespace std; ]; map& ...

  6. AtCoder Grand Contest 003题解

    传送门 \(A\) 咕咕 const int N=1005; char s[N];int val[N],n; int main(){ scanf("%s",s+1),n=strle ...

  7. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  8. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  9. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

随机推荐

  1. Codeforces 558C Amr and Chemistry

    题意: n个数.每次能够选一个数 让其 *=2 或者 /=2 问至少操作多少次使得全部数相等. 思路: 对于每一个数,计算出这个数能够变成哪些数,以及变成那个数的最小步数,用两个数组保存 cnt[i] ...

  2. 全局钩子 实例(不使用DLL和使用DLL两种)

    大家应该都知道,全局消息钩子要依赖于一个DLL才能够正常工作.于是呢,我也就理所当在地认为全局钩子都要依赖于一个DLL才能正常工作的,我想大部分人肯定和我一样也这么认为的. 但实际上不是这样的.有某些 ...

  3. LeetCode 112 Path Sum(路径和)(BT、DP)(*)

    翻译 给定一个二叉树root和一个和sum, 决定这个树是否存在一条从根到叶子的路径使得沿路全部节点的和等于给定的sum. 比如: 给定例如以下二叉树和sum=22. 5 / \ 4 8 / / \ ...

  4. maven依赖排除

    单依赖过滤 同依赖过滤直接处理:可以过滤一个或者多个,如果过滤多个要写多个<exclusion>. <dependency> <groupId>org.apache ...

  5. caioj1465&&poj1024: 【AC自动机】地图匹配

    刷的第二题AC自动机,这题简直了.. 用询问的串建AC自动机,然后...爆搜! ACBB                  ACBBACCA                  A  AABBC     ...

  6. maven安装的详细步骤

    1.下载maven的bin,在apache官方网站下载.window系统下的下载红色方框的 2.解压后, 把bin的位置设在环境变量里,新建环境变量 MAVEN_HOME.这个配置是方便以后更换mav ...

  7. MYSQL进阶学习笔记十:MySQL慢查询!(视频序号:进阶_23-24)

    知识点十一:MySQL 慢查询的应用(23) 一.慢查询定义 MySQL记录下查询超过指定时间的语句,我们将超过指定时间的SQL语句查询称为慢查询. 查看时间限制 show variables lik ...

  8. codeforces 450C. Jzzhu and Chocolate 解题报告(449A)

    题目链接:http://codeforces.com/contest/450/problem/C 题目意思:给出一个 n * m 大小的chocolate bar,你需要在这个bar上切 k 刀,使得 ...

  9. Python的多进程锁的使用

    很多时候,我们需要在多个进程中同时写一个文件,如果不加锁机制,就会导致写文件错乱 这个时候,我们可以使用multiprocessing.Lock() 我一开始是这样使用的: import multip ...

  10. bzoj1207 [HNOI2004]打鼹鼠——LIS

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1207 这题和求LIS有点像,打这一只鼹鼠一定可以从打上一只鼹鼠转移过来: 所以不用考虑机器人 ...