大意: 若一个序列存在两个数的积为完全平方数, 则为好序列. 给定序列$a$, 每次询问求子区间$[l,r]$最少修改多少次可以成为好序列, 每次修改可以任选素数$p$, 任选一个数乘或除$p$.

$dp_{x,y}$表示状态为$x$删除$y$个因子的最大位置

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int N = 1e7+10;
int n, q, ans[N];
int ss[20], dp[N][10], L[N];
vector<int> g[N], p[N]; int main() {
scanf("%d%d", &n, &q);
REP(i,1,n) {
int x;
scanf("%d", &x);
int mx = sqrt(x+0.5);
REP(j,2,mx) if (x%j==0) {
int t = 0;
while (x%j==0) t^=1,x/=j;
if (t) p[i].pb(j);
}
if (x) p[i].pb(x);
}
REP(i,1,q) {
int r;
scanf("%d%d",L+i,&r);
g[r].pb(i);
}
REP(i,1,n) {
int sz = p[i].size(), mx = (1<<sz)-1;
REP(s,0,mx) {
int x = 1, y = 0;
REP(j,0,sz-1) {
if (s>>j&1) x*=p[i][j];
else ++y;
}
REP(j,0,15) ss[j+y]=max(ss[j+y],dp[x][j]);
}
for (auto j:g[i]) {
int now = 0;
while (ss[now]<L[j]) ++now;
ans[j] = now;
}
REP(s,0,mx) {
int x = 1, y = 0;
REP(j,0,sz-1) {
if (s>>j&1) x*=p[i][j];
else ++y;
}
dp[x][y] = i;
}
}
REP(i,1,q) printf("%d\n",ans[i]);
}

Make Square CodeForces - 1028H (dp)的更多相关文章

  1. hdu 1398 Square Coins(简单dp)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Pro ...

  2. Two Melodies CodeForces - 813D (DP,技巧)

    https://codeforces.com/problemset/problem/813/D dp[i][j] = 一条链以i结尾, 另一条链以j结尾的最大值 关键要保证转移时两条链不能相交 #in ...

  3. Consecutive Subsequence CodeForces - 977F(dp)

    Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...

  4. codeforces的dp专题

    1.(467C)http://codeforces.com/problemset/problem/467/C 题意:有一个长为n的序列,选取k个长度为m的子序列(子序列中不能有位置重复),求所取的k个 ...

  5. HDU 6125 Free from square 状态压缩DP + 分组背包

    Free from square Problem Description There is a set including all positive integers that are not mor ...

  6. HDU 5903 Square Distance (贪心+DP)

    题意:一个字符串被称为square当且仅当它可以由两个相同的串连接而成. 例如, "abab", "aa"是square, 而"aaa", ...

  7. HDU1398:Square Coins(DP水题)

    Square Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tota ...

  8. Codeforces 721C [dp][拓扑排序]

    /* 题意:给你一个有向无环图.给一个限定t. 问从1点到n点,在不超过t的情况下,最多可以拜访几个点. 保证至少有一条路时限不超过t. 思路: 1.由无后向性我们可以知道(取决于该图是一个DAG), ...

  9. CodeForces 607C (DP) Hard problem

    题目:这里 题意:给定n个字符串,每个字符串可以进行一项操作,就是将这个字符串交换,就是该字符串的第一个和最后一个交换,第二个和倒数第二个交换,以此类推,当然可以选择对于 该字符串进行或不进行这项操作 ...

随机推荐

  1. JVM 字节码的结构

    编译的.class文件,可以用javap进行反编译 javap Test.class javap -c Test.class javap -verbose Test.class 1.创建MyTest1 ...

  2. Laravel--文件管理及上传自定义目录及文件名

    laravel 上传 php 需要开启 fileinfo 扩展 先看一个例子: $file = $request->file('shopimg'); $path = $file->stor ...

  3. 源码分析关于SpringBoot2.x版本与1.5版本之间的问题

    1.Social包在SpringBoot2.x移除问题 spring-boot-autoconfigure1.5x版本中支持facebook,领英和推特官方文档:https://docs.spring ...

  4. Vue CLI3和Vue CLI2环境搭建

    关于 Vue CLI 旧版本的安装以及创建项目 1.搭建 vue 的开发环境 ,安装 vue 的脚手架工具 官方命令行工具 npm install --global vue-cli / cnpm in ...

  5. 使用SoapUI发送Post请求

    https://www.cnblogs.com/xiaowangzi1110/p/8544264.html 使用SoapUI发送Post请求 SoapUI作为一个开源的工具,其具备强大的功能.易用的界 ...

  6. RestSharp - Ignore SSL errors

    项目启动时,添加下面代码: 项目启动时,添加 public App() { ServicePointManager.ServerCertificateValidationCallback += (se ...

  7. org/apache/curator/RetryPolicy at com.alibaba.dubbo.remoting.zookeeper.curator.CuratorZookeeperTransporter.connect(CuratorZookeeperTransporter.java:26)

    使用dubbo服务,启动项目报错: org/apache/curator/RetryPolicy at com.alibaba.dubbo.remoting.zookeeper.curator.Cur ...

  8. k8s记录-flanneld+docker网络部署(四)

    1)程序准备tar xvf flannel-v0.10.0-linux-amd64.tar.gz mkdir -p /data/projects/common/kubernetes/{bin,cfg, ...

  9. 使用SampleRateConverter对音频采样率进行转换

    java sound resource SampleRateconverter.java(接近于官方源码) 输入目标采样率,输入文件,输出文件.食用方便;p 比如 SampleRateConverte ...

  10. 【kubectl 原理】kubectl 命令执行的时候究竟发生了什么(kubectl、apiserver、etcd)

    参考: https://www.yangcs.net/posts/what-happens-when-k8s/ 总而言之,kubectl命令执行的时候,先在本地封装请求,然后过kube-apiserv ...