大意: 若一个序列存在两个数的积为完全平方数, 则为好序列. 给定序列$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. CEF3开发者系列之Cookies管理和共享<转>

    原帖地址:https://www.cnblogs.com/guolixiucai/p/6994559.html 涉及网页登录相关的技术,Cookies肯定是忽略不了的.由于项目的需要,要做一个双核的产 ...

  2. useEffect代替常用生命周期函数(三)

    在用Class制作组件时,经常会用生命周期函数,来处理一些额外的事情(副作用:和函数业务主逻辑关联不大,特定时间或事件中执行的动作,比如Ajax请求后端数据,添加登录监听和取消登录,手动修改DOM等等 ...

  3. variant变异 | Epigenome表观基因组 | Disease-susceptible gene 疾病易感基因

    paper:cepip: context-dependent epigenomic weighting for prioritization of regulatory variants and di ...

  4. Linux中进程的几种状态

    linux是一个多用户,多任务的系统,可以同时运行多个用户的多个程序,就必然会产生很多的进程,而每个进程会有不同的状态. Linux进程状态:R (TASK_RUNNING),可执行状态. 只有在该状 ...

  5. 网站安全统一监测平台(WebPecker)

    网站安全统一监测平台(WebPecker)_智恒科技http://www.zhihengit.com/html/pro/chanpinfenlei1/2016/0511/135.html [SQL注入 ...

  6. win cmd 设置代理

    windows: HTTP(S)代理服务器:127.0.0.1:5783 SOCKS代理服务器:127.0.0.1:5789 set 2 set http_proxy=socks5://127.0.0 ...

  7. Leetcode: Campus Bikes II

    On a campus represented as a 2D grid, there are N workers and M bikes, with N <= M. Each worker a ...

  8. Python3基础 二、八、十、十六进制转换

             Python : 3.7.3          OS : Ubuntu 18.04.2 LTS         IDE : pycharm-community-2019.1.3    ...

  9. window.location.href重定向失败的问题

    如题,在js中通过window.location.href=URL来跳转到另一个页面(也可以是另一个项目的另一个页面). 打开的页面地址是:www.a.com/project1/index 要跳转的页 ...

  10. linux非root用户安装4.0.14版本redis

    先到官网https://redis.io/download下安装包,现在最新是5.0.5版本,可惜点击下载后被windows禁了,那就下4版本的,往下看Other versions的Old(4.0), ...