大意: 若一个序列存在两个数的积为完全平方数, 则为好序列. 给定序列$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. shell获取今天、明天、昨天、n天、周、月、年日期

    1.获取今天日期 $ date -d now +%Y-%m-%d   或者$ date +%F 1    2 2.获取明天日期 $ date -d next-day +%Y-%m-%d$ date - ...

  2. Mosquitto配置----日志设置

    https://blog.csdn.net/u012377333/article/details/71101725 # ======================================== ...

  3. NAXSI means Nginx Anti XSS & SQL Injection. NAXSI is an open-source, high performance, low rules maintenance WAF for NGINX

    nbs-system/naxsi: NAXSI is an open-source, high performance, low rules maintenance WAF for NGINXhttp ...

  4. Angular中使用ECharts图表

    1.安装: npm install echarts --save 2.在 TypeScript 文件中导入echarts import * as echarts from 'echarts'; 3.根 ...

  5. 图片缩放——利用layui的滑块

    @layui官网文档.@参考博客 参考博客中能实现,但是效果差强人意,在前辈的基础上进行了改造,并支持了动态多图列表 <%@ page language="java" con ...

  6. ThreadLocal Memory Leak in Java web application - Tomcat

    ThreadLocal variables are infamous for creating memory leaks. A memory leak in Java is amount of mem ...

  7. 使用docker搭建FastDFS文件系统

    1.首先下载FastDFS文件系统的docker镜像 docker search fastdfs 2.使用docker镜像构建tracker容器(跟踪服务器,起到调度的作用): docker run ...

  8. 深度技术W10系统中绑定MAC地址和IP地址的设置技巧

    深度技术W10系统中绑定MAC地址和IP地址的设置技巧分享给大家,感兴趣的用户,请一起来了解下,以备以后作参考,具体如下:1.点击“开始——搜索”,输入CMD命令,然后在CMD上右键选择以管理员身份运 ...

  9. git的使用学习(一)git的简介和安装

    Git简介 Git是什么? Git是目前世界上最先进的分布式版本控制系统(没有之一). Git有什么特点?简单来说就是:高端大气上档次! 那什么是版本控制系统? 如果你用Microsoft Word写 ...

  10. 基于vue-cli、elementUI的Vue简单入门例子

    vue-cli.elementUI的安装教程请看: https://www.cnblogs.com/joe235/p/12013818.html 把HelloWorld.vue文件修改为: <t ...