Make Square CodeForces - 1028H (dp)
大意: 若一个序列存在两个数的积为完全平方数, 则为好序列. 给定序列$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)的更多相关文章
- hdu 1398 Square Coins(简单dp)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Pro ...
- Two Melodies CodeForces - 813D (DP,技巧)
https://codeforces.com/problemset/problem/813/D dp[i][j] = 一条链以i结尾, 另一条链以j结尾的最大值 关键要保证转移时两条链不能相交 #in ...
- Consecutive Subsequence CodeForces - 977F(dp)
Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...
- codeforces的dp专题
1.(467C)http://codeforces.com/problemset/problem/467/C 题意:有一个长为n的序列,选取k个长度为m的子序列(子序列中不能有位置重复),求所取的k个 ...
- HDU 6125 Free from square 状态压缩DP + 分组背包
Free from square Problem Description There is a set including all positive integers that are not mor ...
- HDU 5903 Square Distance (贪心+DP)
题意:一个字符串被称为square当且仅当它可以由两个相同的串连接而成. 例如, "abab", "aa"是square, 而"aaa", ...
- HDU1398:Square Coins(DP水题)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Codeforces 721C [dp][拓扑排序]
/* 题意:给你一个有向无环图.给一个限定t. 问从1点到n点,在不超过t的情况下,最多可以拜访几个点. 保证至少有一条路时限不超过t. 思路: 1.由无后向性我们可以知道(取决于该图是一个DAG), ...
- CodeForces 607C (DP) Hard problem
题目:这里 题意:给定n个字符串,每个字符串可以进行一项操作,就是将这个字符串交换,就是该字符串的第一个和最后一个交换,第二个和倒数第二个交换,以此类推,当然可以选择对于 该字符串进行或不进行这项操作 ...
随机推荐
- SSM项目启动报错WEB-INF\lib\javax.servlet-api-4.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10
错误信息: validateJarFile(D:\tomcat_ryxunit\webapps\ryx_unit\WEB-INF\lib\javax.servlet.jar) - jar not lo ...
- Java性能分析神器-JProfiler详解(转)
前段时间在给公司项目做性能分析,从简单的分析Log(GC log, postgrep log, hibernate statitistic),到通过AOP搜集软件运行数据,再到PET测试,感觉时间花了 ...
- java MVEL2/Spring EL表达式、直接调用、反射性能实测
import java.io.Serializable; import java.lang.reflect.Field; import java.util.HashMap; import java.u ...
- OpenGL ES: (4) EGL API详解 (转)
上一节我们初步学习了 OpenGL ES.EGL.GLSL 的相关概念,了解了它们的功能,以及它们之间的关联.我们知道了 EGL 是绘制 API(比如 OpenGL ES)与 底层平台窗口系统之间的接 ...
- Java获取系统基础参数信息
一.JVM已经帮我们读取了系统信息 public void testSystemParam(){ Properties p = System.getProperties(); Iterator it ...
- Leetcode: Capacity To Ship Packages Within D Days
A conveyor belt has packages that must be shipped from one port to another within D days. The i-th p ...
- matlab优化函数fminunc
一起来学演化计算-matlab优化函数fminunc 觉得有用的话,欢迎一起讨论相互学习~Follow Me fminunc 求无约束多变量函数的最小值 非线性编程求解器 找到指定问题的最小值,\(m ...
- Python - Django - 模板语言之 Filters(过滤器)
通过管道符 "|" 来使用过滤器,{{ value|过滤器:参数 }} Django 的模板语言中提供了六十个左右的内置过滤器 urls.py: from django.conf. ...
- NETTY keeplive 参数,心跳检测
当设置为true的时候,TCP会实现监控连接是否有效,当连接处于空闲状态的时候,超过了2个小时,本地的TCP实现会发送一个数据包给远程的 socket,如果远程没有发回响应,TCP会持续尝试11分钟, ...
- 透过SourceTree再谈Git
初出茅庐之基础篇 1. Download SourceTree from: https://www.sourcetreeapp.com/ 2.Complete the installation. 3. ...