Tokitsukaze has a sequence of length nn, denoted by aa.
Tokitsukaze can merge two consecutive elements of aa as many times as she wants. After each operation, a new element that equals to the sum of the two old elements will replace them, and thus the length of aa will be reduced by 11.
Tokitsukaze wants to know the maximum possible number of elements that are multiples of pp she can get after doing some operations (or doing nothing) on the sequence aa.
InputThere are several test cases.

The first line contains an integer TT (1≤T≤20)(1≤T≤20), denoting the number of test cases. Then follow all the test cases.
For each test case, the first line contains two integers nn and pp (1≤n,p≤105)(1≤n,p≤105), denoting the length of the sequence and the special number, respectively.
The second line contains nn integers, where the ii-th integer aiai (1≤ai≤105)(1≤ai≤105) is the ii-th element of aa.
It is guaranteed that the sum of nn in all test cases is no larger than 106106.
OutputFor each test case, output in one line the maximum possible number of elements that are multiples of pp after doing some operations.
Sample Input

2
5 3
2 1 3 2 1
3 1
123 456 789

Sample Output

3
3

Sponsor

题意:

  一个序列,每次可以将序列相邻的两个数相加生成一个新的和替代这两个元素,求最终序列里为 p 的倍数的元素最多可能为多少个

思路:

  前缀和

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
//#define sort(a,n,int) sort(a,a+n,less<int>()) #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db; const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
const int N=2e5+10;
const int mod=1e9+7; int n = 0;
int p = 0;
int counter[N] = {0};
int sum[N] = {0};
int ans[N] = {0};
int K[N] = {0};
void init_K()
{
for(int i = 0;i<p;i++)
{
K[i] = -1;
}
}
int main()
{
int T;
cin >> T;
while(T--)
{
scanf("%d%d",&n ,&p);
init_K();
for(int i = 1;i<=n;i++)
{
int temp = 0;
cin >> temp;
counter[i] = (counter[i-1] + temp)%p;
}
for(int i = 0;i<=n;i++)
{
sum[i] = K[counter[i]];
K[counter[i]] = i;
}
for(int i = 1;i<=n;i++)
{
if(sum[i] != -1)
{
ans[i] = max(ans[i-1] , ans[sum[i]] + 1);
}
else
{
ans[i] = ans[i-1];
}
}
printf("%d\n",ans[n]);
}
return 0;
}

  

附第一遍错误思路OT代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include <vector>
#include <iterator>
#include <utility>
#include <sstream>
#include <limits>
#include <numeric>
#include <functional>
using namespace std;
#define gc getchar()
#define mem(a) memset(a,0,sizeof(a))
//#define sort(a,n,int) sort(a,a+n,less<int>()) #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef char ch;
typedef double db; const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const int maxn=1e5+10;
const int maxm=100+10;
const int N=2e5+10;
const int mod=1e9+7; int counter[100005] = {0};
void init()
{
for(int i = 0;i < 100005;i++)
counter[i] = 0;
}
int main()
{
int T = 0;
int n = 0, p = 0;
int temp = 0;
int ans = 0;
cin >> T;
while(T--)
{
init();
ans = 0;
cin >> n >> p;
for(int i = 0;i<n;i++)
{
cin >> temp;
counter[temp % p] += 1;
}
ans += counter[0];
for(int i = 1;i <= p/2;i++)
{
ans += min(counter[i],counter[p-i]);
}
if(p % 2 == 0)
{
ans += counter[p/2]/2;
}
cout << ans << endl;
}
return 0;
}

  

D - Tokitsukaze and Multiple的更多相关文章

  1. hdu 6794 Tokitsukaze and Multiple 前缀和思想+思维

    题意: t组输入,给你一个长度为n的数组,你每次可以从数组中找到a[i]和a[i+1],然后用a[i]+a[i+1]这个新元素来覆盖掉a[i]和a[i+1]的位置(1<=i<n),从而数组 ...

  2. Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ...

    Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define ... 这个错误是因为有两个相 ...

  3. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  4. [LeetCode] Read N Characters Given Read4 II - Call multiple times 用Read4来读取N个字符之二 - 多次调用

    The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...

  5. SharePoint "System.Data.SqlClient.SqlException (0x80131904): Parameter '@someColumn' was supplied multiple times.“

    最近在处理SharePoint Office365的相关开发的时候发现了这样一个奇怪的现象: 无法通过API更新Editor field,只要已更新就会throw Exception,由于是Offic ...

  6. 2012Chhengdu K - Yet Another Multiple Problem

    K - Yet Another Multiple Problem Time Limit:20000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  7. JAVA实现AES 解密报错Input length must be multiple of 16 when decrypting with padded cipher

    加密代码 /**解密 * @param content 待解密内容 * @param password 解密密钥 * @return */ public static byte[] decrypt(b ...

  8. scala - multiple overloaded alternatives of method bar define default arguments

    同名同位置默认参数不能overload def bar(i:Int,s:String="a"){} def bar(i:String,s:String="b") ...

  9. 基于Picture Library创建的图片文档库中的上传多个文件功能(upload multiple files)报错怎么解决?

    复现过程 首先,我创建了一个基于Picture Library的图片文档库,名字是 Pic Lib 创建完毕后,我点击它的Upload 下拉菜单,点击Upload Picture按钮 在弹出的对话框中 ...

  10. 多文档上传(upload multiple documents)功能不能使用怎么办?

    问题描述: 在SharePoint 2010的文档库里选择documents标签,然后选择upload document下拉菜单,你会发现upload multiple documents那个按钮是灰 ...

随机推荐

  1. 8086汇编(16位汇编)学习笔记00.DEBUG命令使用解析及范例大全

    转载自:https://bpsend.net/thread-99-1-1.html 启动 Debug,它是可用于测试和调试 MS-DOS 可执行文件的程序. Debug [[drive:][path] ...

  2. Cursor+Claude-3.7-sonnet 生成一整套APP原型图:AI英语口语学习助手app

    一.引言 在 AI 技术快速发展的今天,特别是随着 Claude 3.7 的发布,AI 辅助设计和开发已经达到了一个新的高度. 本文将详细介绍如何使用 Cursor IDE 配合 Claude-3.7 ...

  3. 洛谷 SP7258 SUBLEX - Lexicographical Substring Search

    洛谷 SP7258 SUBLEX - Lexicographical Substring Search Problem 先给你一个字符串s,后有T次询问.询问这个字符串的所有本质不同的子串中第k小的子 ...

  4. GDAL 2.X升级3.X需要注意的问题总结

    1 引言 最近终于将使用的GDAL 2.X升级到成了3.X版本,总结一下遇到的各种问题. 2 详论 2.1 数据路径 GDAL 3.X以后深度依赖PROJ库,以前只是可选构建项,现在已经是必须构建项了 ...

  5. 「Note」模板速查

    代码 #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long l ...

  6. Vue获取钉钉免登陆授权码(vue中的回调函数实践)

    作者:故事我忘了¢个人微信公众号:程序猿的月光宝盒 目录 1.背景 2.技术栈 3.需求 4.实现步骤 4.1 配合webpack安装对应的npm包 4.2 抽取获得code的js方法 4.3 在需要 ...

  7. Dify实战案例:AI邮件批量发送器!

    在 Dify 的使用中,有很多很实用并且很好玩的案例,例如今天给大家介绍这个"AI邮件批量发送器". 在没有 Dify 之前,我们要实现邮件的批量发送是件很难的事,不但要写很长的代 ...

  8. el-popover无法弹出的问题解决

    1.不能再el-popover上⾯使⽤v-if进⾏显⽰隐藏,应该⽤v-show2.在每⼀个el-popover上都增加⼀个ref确定每个el-popover都是唯⼀的,:ref="`node ...

  9. CAE技术的局限性讨论-CAE咨询

    计算机辅助工程(Computer-Aided Engineering, CAE)技术是现代工程领域中不可或缺的一部分,它通过数值模拟和计算分析,为工程设计和优化提供了强大的工具.然而,就像任何技术一样 ...

  10. XXL-JOB v3.1.1 | 分布式任务调度平台(Dify工作流调度增强)

    Release Notes 1.[调整]AI任务(difyWorkflowJobHandler)优化:针对 "baseUrl.apiKey" 等Dify配置信息,从执行器侧文件类配 ...