C. Yet Another Counting Problem

思路:数学题,没有什么思路就暴力打表找规律,我们可以发现以lcm[a,b]为一个周期,这个周期内的特殊数的个数是确定的。那么我们就把[1,lcm]内的特殊数暴力找出来。dp[i]代表的是前i个数中有多少个特殊数。

对于输入的l和r,我们只需要看他们中分别有多少个lcm以及对lcm取余是多少,然后加起来就可以了。分别对l和r计算出这个数,然后再用前缀和思想

/*
最k大值最小 ---> 二分答案*/
#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <deque>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define _for(i,a,b) for( int i = (a); i < (b); ++i)
#define _rep(i,a,b) for( int i = (a); i <= (b); ++i)
#define for_(i,a,b) for( int i = (a); i >= (b); -- i)
#define rep_(i,a,b) for( int i = (a); i > (b); -- i)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define hash Hash
#define all(x) x.begin(),x.end()
#define next Next
#define f first
#define s second
using namespace std;
const int N = 2e5 + 10;
const double eps = 1e-9;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
inline LL read() {LL s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;
}
LL sum[N << 1];
int main()
{IOS;string s;int T;cin >> T;while(T --){LL a, b, c;cin >> a >> b >> c;if(a > b) swap(a,b);LL lcm = a / __gcd(a,b) * b;_for(i,0,lcm){sum[i] = 0;if((i%a)%b!=(i%b)%a) sum[i] = 1;if(i)sum[i] += sum[i - 1];}while(c--){LL l, r;cin >> l >> r;if(r < b) cout << "0 ";else{l --;LL Le = l / lcm * sum[lcm - 1] + sum[l % lcm];LL Ri = r / lcm * sum[lcm - 1] + sum[r % lcm];cout << Ri - Le << " ";}}cout << endl;}return 0;
}

题意:
给出n个数,每个数权值不超过k,现在要从这些数中选出一些组成若干个序列,要求每个数恰好被选入一个序列之中。
并且满足限制:ci表示不小于i的数的个数,对于1≤i≤k都要满足。
现在问最少构成多少个序列。
保证c1≥c2≥⋯≥ck。

因为很明显大的数c就越小那么我们就从大到小枚举,用一个数组记录各个数组长度然后早到第一个len小于(这里不能等因为等的话加进这个数总len就超了)c[a[i]]的数组,我们有一个操作就是可以把长度设成负数就可以用upper_bound()

代码如下:

#include <iostream>
#include <cstdio>
#include <stack>
#include <sstream>
#include <vector>
#include <map>
#include <cstring>
#include <deque>
#include <cmath>
#include <deque>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <set>
#define mid ((l + r) >> 1)
#define Lson rt << 1, l , mid
#define Rson rt << 1|1, mid + 1, r
#define ms(a,al) memset(a,al,sizeof(a))
#define _for(i,a,b) for( int i = (a); i < (b); ++i)
#define _rep(i,a,b) for( int i = (a); i <= (b); ++i)
#define for_(i,a,b) for( int i = (a); i >= (b); -- i)
#define rep_(i,a,b) for( int i = (a); i > (b); -- i)
#define lowbit(x) ((-x) & x)
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
#define hash Hash
#define all(x) x.begin(),x.end()
#define next Next
#define f first
#define s second
using namespace std;
const int N = 2e5 + 10;
const double eps = 1e-9;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
inline LL read() {LL s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;
}
int  a[N << 1], b[N << 1];
vector<int> ans[N];
int sz[N];//统计数组长度;
int main()
{int n, m;IOS;cin >> n >> m;_for(i,1,n+1) cin >> a[i];_for(i,1,m+1) cin >> b[i];sort(a+1,a+n+1);int arrsum = 0;for_(i,n,1){if(!arrsum){sz[++ arrsum] --;ans[arrsum].push_back(a[i]);}else{int pos = upper_bound(sz+1,sz+1+arrsum,-b[a[i]]) - sz;if(pos > arrsum) arrsum = pos;sz[pos] --;ans[pos].push_back(a[i]);}}cout << arrsum << endl;_for(i,1,arrsum+1){cout << -sz[i] << " ";for(auto it : ans[i])cout << it << " ";cout << endl;}return 0;
}

Educational Codeforces Round 86 (Rated for Div. 2)c和d相关推荐

  1. Educational Codeforces Round 86 (Rated for Div. 2) Apr/26/2020 22:35UTC+8

    Educational Codeforces Round 86 Rated for Div. 2 A. Road To Zero B. Binary Period(找最小周期) C. Yet Anot ...

  2. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

  3. Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...

  4. Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...

  5. Educational Codeforces Round 37 (Rated for Div. 2) 1

    Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...

  6. Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)

    Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...

  7. Educational Codeforces Round 114 (Rated for Div. 2) D. The Strongest Build 暴力 + bfs

    传送门 文章目录 题意: 思路: 题意: 你有nnn个装备槽,每个槽里面有cic_ici​个力量加成,对于每个槽只能选一个力量加成,现在给你mmm个力量组合[b1,b2,...,bn][b_1,b_2 ...

  8. Educational Codeforces Round 72 (Rated for Div. 2) D. Coloring Edges dfs树/拓扑找环

    传送门 文章目录 题意: 思路: 题意: 给你一张图,你需要给这个图的边染色,保证如果有环那么这个环内边的颜色不全相同,输出染色方案和用的颜色个数. n,m≤5e3n,m\le5e3n,m≤5e3 思 ...

  9. Educational Codeforces Round 111 (Rated for Div. 2) D. Excellent Arrays 组合数学

    传送门 文章目录 题意: 思路: 题意: 给你一个数组aia_iai​,定义一个数组是好的当且仅当对于所有iii都有ai!=ia_i!=iai​!=i.定义f(a)f(a)f(a)表示数组aaa中i& ...

最新文章

  1. tlb存的什么_什么是MMU,TLB
  2. Android 获取屏幕尺寸与密度
  3. 高并发网络编程之epoll详解
  4. IOS对plist配置文件的读写操作
  5. Hystrix配置参数查找方式
  6. camunda流程引擎如此简单「四」
  7. C/C++人机猜拳游戏
  8. WCF三种通信模式(转)
  9. linux 运行eclipse,解决Linux下Eclipse启动错误
  10. 配对碱基链(信息学奥赛一本通-T1135)
  11. igm焊接机器人基本操作_焊接机器人编程与操作
  12. 红米开发版刷机教程_红米K30开发版刷机包(官方完整最新固件升级包MIUI12)
  13. 微信小程序——绘制时钟
  14. 为什么SICP要讨论那么多的初等数学
  15. Ubuntu Qt 无法覆盖文件 错误解决方法
  16. 使用pm2管理项目(指令)
  17. python 将QQ聊天记录生成词云图
  18. 基于cocos2d-lua的shader入门玩转
  19. Android-安卓Canvas画小黄人
  20. 一道面试题:StringBuffer a=new StringBuffer (A); StringBuffer b=new StringBuffer

热门文章

  1. 王爽 汇编语言第三版 监测点9.2 监测点9.3 补全编程,利用jcxz指令,利用loop指令,实现在内存2000H段中查找第一个值为0的字节,
  2. ACMNO.49:一元三次方程求解(主要就是精度问题)
  3. 【Python基础】Python的深浅拷贝讲解
  4. 揭秘三维视觉之结构光原理
  5. 计算机视觉研究生文献和复现哪个更重要?
  6. 强势推荐一位 Python 原创自动化大佬!
  7. 基于Python查找图像中最常见的颜色
  8. 链表问题9——复制含有随机指针节点的链表(进阶)
  9. 8个必备的PHP功能开发
  10. 物联网是地产行业转型的有力推手