zoj 3940E
来源:互联网 发布:毛衣品牌 知乎 编辑:程序博客网 时间:2024/06/05 00:07
题目链接
E - Modulo Query
分析
不要问我为什么,看了题解再yy一下你就懂了.
题解
AC code
#include <cstdio>#include <iostream>#include <vector>#include <queue>#include <algorithm>#include<cmath>#include <cstring>#include <map>#include <iomanip>#define fi first#define se second#define INF 0x3f3f3f3f3f3f3f3fusing namespace std;const int MOD = 1e9+7;const int MAX_P = 2e4+10;const int maxn =2e5+10;const int MAX_V = 5e5+10;const int maxv = 1e6+10;typedef long long LL;typedef long double DB;typedef pair<LL,LL> Pair;LL sum[maxn];Pair interval[maxn];int main(int argc, char const *argv[]) { int T; cin>>T; while (T--) { int n,m; cin>>n>>m; priority_queue<Pair ,std::vector<Pair> ,less<Pair> > Q; Q.push(Pair(m,1)); while (n--) { int s; scanf("%d",&s ); while (Q.top().fi >= s) { Pair tmp = Q.top();Q.pop(); while (!Q.empty() && Q.top().fi == tmp.fi){ tmp.se+=Q.top().se;Q.pop(); } Q.push(Pair(s-1,(tmp.fi+1)/s*tmp.se));//产生在(s-1)内的数的方法总数. if((tmp.fi+1) % s){ Q.push(Pair(tmp.fi % s,tmp.se)); } } } int cnt =0; while (!Q.empty()) { Pair tmp = Q.top();Q.pop(); while (!Q.empty() &&tmp.fi == Q.top().fi ) { tmp.se+=Q.top().se; Q.pop(); } interval[cnt++] = tmp; } //std::cout << "cnt " << cnt << '\n'; sort(interval,interval+cnt); sum[0] = interval[0].se; //std::cout << "sum" << '\n'; for(int i=1 ; i<cnt ; ++i){ sum[i] = sum[i-1]+interval[i].se; //std::cout << sum[i] << '\n'; } int q; cin>>q; int i=0; LL ans =0; while (q--) { i++; int y; scanf("%d", &y); int pos = lower_bound(interval,interval+cnt,Pair(y,0))-interval; LL tmp =0; if(pos < cnt)tmp = sum[cnt-1]-sum[pos-1]; ans = (ans+tmp*i) % MOD; } std::cout << ans << '\n'; } return 0;}
0 0
- zoj 3940E
- ZOJ 2969 模拟 (E)
- ZOJ 3962 E
- ZOJ 1113 u Calculate e
- zoj 1113 u Calculate e
- ZOJ 1113 u Calculate e
- ZOJ 3681 E - Cup 2
- ZOJ 3682 E - Cup 3
- ZOJ 3682 E - Cup 3
- ZOJ 3681 E - Cup 2
- ZOJ 1113: u Calculate e
- ZOJ 1113 u Calculate e
- ZOJ 3326(E)模拟
- ZOJ Monthly March 2013 E & H
- ZOJ-3681 E - Cup 2 dfs
- [dp] zoj 3682 E - Cup 3
- zoj 月赛 E 费用流
- ZOJ Monthly, February 2016 - E:Ellipse
- IMWeb训练营作业------任务计划列表
- 数据库事务、事务四个特性以及三大范式
- unit14 linux中设备的访问
- c语言俩个栈实现一个队列
- Java基础知识总结(绝对经典)
- zoj 3940E
- 括号配对问题
- Logstash学习14_Logstash中文乱码问题
- 问题
- 通过createPackageContext
- shell编程软件学习经验
- MyEclipse 添加Server Librery
- 安装boost库
- access 数据库模糊查询