4724: [POI2017]Podzielno
来源:互联网 发布:免费横道图绘制软件 编辑:程序博客网 时间:2024/06/08 12:22
4724: [POI2017]Podzielno
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 229 Solved: 108
[Submit][Status][Discuss]
Description
B进制数,每个数字i(i=0,1,...,B-1)有a[i]个。你要用这些数字组成一个最大的B进制数X(不能有前导零,不需要
用完所有数字),使得X是B-1的倍数。q次询问,每次询问X在B进制下的第k位数字是什么(最低位是第0位)。
Input
第一行包含两个正整数B(2<=B<=10^6),q(1<=q<=10^5)。
第二行包含B个正整数a[0],a[1],a[2],...,a[B-1](1<=a[i]<=10^6)。
接下来q行,每行一个整数k(0<=k<=10^18),表示一个询问。
Output
输出q行,每行一个整数,依次回答每个询问,如果那一位不存在,请输出-1。
Sample Input
3 3
1 1 1
0
1
2
1 1 1
0
1
2
Sample Output
0
2
-1
2
-1
HINT
Source
鸣谢Claris上传
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std; const int maxn = 1E6 + 10;typedef long long LL; int m;LL sum,B,A[maxn]; inline LL getLL(){ char ch = getchar(); LL ret = 0; while (ch < '0' || '9' < ch) ch = getchar(); while ('0' <= ch && ch <= '9') ret = ret * 10LL + 1LL * (ch - '0'),ch = getchar(); return ret;} int main(){ #ifdef DMC freopen("DMC.txt","r",stdin); #endif B = getLL(); m = getLL(); for (int i = 0; i < B; i++) { A[i] = getLL(); sum += 1LL * i * A[i]; sum %= (B - 1); } if (sum) --A[sum]; A[B] = 1E18 + 233LL; for (int i = 1; i < B; i++) A[i] += A[i - 1]; for (int i = 0; i < B; i++) A[i] -= 1LL; while (m--) { LL x = getLL(); int pos = lower_bound(A,A + B + 1,x) - A; printf("%d\n",pos == B ? -1 : pos); } return 0;}
0 0
- 4724: [POI2017]Podzielno
- BZOJ 4724 POI2017 Podzielno 数论
- bzoj 4724: [POI2017]Podzielno 数学
- BZOJ4724 [POI2017]Podzielno
- bzoj4724 [POI2017]Podzielno 数论
- BZOJ4724: [POI2017]Podzielno
- BZOJ4726: [POI2017]Sabota?
- bzoj4723 [POI2017]Flappy Bird
- bzoj4726 [POI2017]Sabota?
- BZOJ4726 [POI2017]Sabota?
- 【BZOJ】4726 [POI2017] Sabota?
- BZOJ 4726 [POI2017] Sabota?
- BZOJ4723 [POI2017]Flappy Bird
- 4726: [POI2017]Sabota?
- 4723: [POI2017]Flappy Bird
- BZOJ4727: [POI2017]Turysta
- [POI2017] Flappy Bird 题解
- 4727: [POI2017]Turysta
- 面向对象的陷阱——构造器的陷阱
- ANDROID LOG信息分析
- NYOJ123 士兵杀敌(四)(树状数组,插线问点)
- 获取屏幕旋转事件
- 数据存储之SQLite与LitePal<一>
- 4724: [POI2017]Podzielno
- 一个简单的爬虫开发
- Differences and Similarities Between Index Coalesce and Shrink Space
- linux中使用apt-get安装的文件位置
- mybatis动态执行自定义sql
- Android流畅性优化必备基础知识点---线程调度方式
- hdu 2018 母牛的故事
- HDU 4507 吉哥系列故事――恨7不成妻 (平方拆解 + *数位DP 总结)
- centos6.5 解决python2.6.6交互模式下方形键和退格键乱码的情况