用map是卡着过去的。。题解用vector+离散化后常数小了十倍。。

总之就是把所有模数给保存下来然后离散化,再去匹配一下即可,最后有个细节

自己的

#include<bits/stdc++.h>
using namespace std;
#define ll int
#define maxn 200005
ll n,k,a[maxn];
map<ll,ll>mp[];
int main(){
cin>>n>>k;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
ll tmp=a[i],len=;
while(tmp)len++,tmp/=;
mp[len][a[i]%k]++;
}
ll ans=;
for(int i=;i<=n;i++){
ll tmp=a[i],tmp2=a[i],len=;
while(tmp2)len++,tmp2/=;
for(int j=;j<=;j++){
tmp=tmp*%k;
ans+=mp[j][(k-tmp)%k];
if(j==len && a[i]%k==(k-tmp)%k)ans--;
} }
cout<<ans<<endl;
}

题解的

#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); i++)

typedef long long li;

using namespace std;

const int N =  *  + ;
const int LOGN = ; int n, k;
int a[N];
int len[N];
vector<int> rems[LOGN];
int pw[LOGN]; int main() {
scanf("%d%d", &n, &k);
forn(i, n) scanf("%d", &a[i]); pw[] = ;
forn(i, LOGN - )
pw[i + ] = pw[i] * % k; forn(i, n){
int x = a[i];
while (x > ){
++len[i];
x /= ;
}
rems[len[i]].push_back(a[i] % k);
} forn(i, LOGN)
sort(rems[i].begin(), rems[i].end()); li ans = ;
forn(i, n){
for (int j = ; j < LOGN; ++j){
int rem = (a[i] * li(pw[j])) % k;
int xrem = (k - rem) % k;
auto l = lower_bound(rems[j].begin(), rems[j].end(), xrem);
auto r = upper_bound(rems[j].begin(), rems[j].end(), xrem);
ans += (r - l);
if (len[i] == j && (rem + a[i] % k) % k == )
--ans;
}
} printf("%lld\n", ans);
return ;
}

最新文章

  1. [LeetCode] Remove Duplicates from Sorted Array
  2. EditText监听键盘输入
  3. [UML][转]UML类图符号 各种关系说明以及举例
  4. C# 跨线程访问或者设置UI线程控件的方法
  5. unauthenticated user reading from net
  6. Memcache+Tomcat9集群实现session共享(非jar式配置, 手动编写Memcache客户端)
  7. jsf taglib定义函数
  8. Web网页中动态数据区域的识别与抽取 Dynamical Data Regions Identification and Extraction in Web Pages
  9. Ajax基础知识(二)
  10. Android 再按一次退出程序三种办法
  11. NEO从入门到开窗(2) - 智能合约的面相
  12. ROS机器人程序设计(原书第2版)补充资料 (壹) 第一章 ROS系统入门
  13. pig基础知识总结
  14. 找jar包的网站 还没用过2017.12.19
  15. Django ORM多表操作
  16. Elasticsearch简介和安装对比
  17. qt 在窗口上画框
  18. System.ComponentModel.DataAnnotations.Schema.TableAttribute 同时存在于EntityFramework.dll和System.ComponentModel.DataAnnotations.dll中
  19. 资源中心的ES 服务的COM.IFLYTEK.ERSP.API.RESOURCEAPI 接口注册ZOOKEEPER失败,解决记录
  20. luogu1514 [NOIp2010]引水入城 (bfs+记忆化搜索)

热门文章

  1. Codeforces 1166A - Silent Classroom
  2. pytong下安装安装SK-Learn
  3. [AH2017/HNOI2017]单旋
  4. websocket接口测试
  5. 无LoadLibrary获取指定模块基址
  6. Impala查询执行过程
  7. Hive HA基本原理
  8. zabbix_agentd 报错
  9. 【JZOJ5730】【luoguP2146】【Comet OJC0396】软件包管理器
  10. LUOGU P3048 [USACO12FEB]牛的IDCow IDs(组合数)