[cf1495E]Qingshan and Daniel
选择其中卡片总数较少的一类,当相同时选择$t_{1}$所对应的一类(以下记作$A$类)
如果$t_{1}$不是$A$类,就先对$t_{1}$操作一次(即令$a_{1}$减少1)
下面,问题即不断删去$A$类中的一张卡片,再删除另一类中的一张卡片,直至$A$中卡片被删光
事实上,$A$类中卡片删除顺序与最终另一类卡片剩余卡片的位置无关,具体证明考虑交换$A$中两张相邻卡片的删除顺序,并分类讨论来说明不影响即可
由此,不妨假设$A$类卡片是从左到右依次删除(即删完一叠后删除下一叠),每一张删除时都找到下一叠未完全删除的非$A$类卡片,并删除其中一张
对于这个过程,可以用下述方法维护:
记录一个变量$s$,表示$A$中当前还有几张卡片没有对应的删除
若当前为$A$类,令$s$加上这一叠的卡片数
若当前为$B$类,从中删除$\min(s,这一叠的卡片数)$,同时$s$也减去这个值
由于是环,所以重复一次即可
时间复杂度为$o(n)$,可以通过

1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 5000005
4 #define mod 1000000007
5 #define ll long long
6 int n,m,p,x,y,seed,base,a[N],t[N],ans[N];
7 ll s,tot[3];
8 int rnd(){
9 int ans=seed;
10 seed=(1LL*seed*base+233)%mod;
11 return ans;
12 }
13 int main(){
14 scanf("%d%d",&n,&m);
15 int lst=0;
16 for(int i=1;i<=m;i++){
17 scanf("%d%d%d%d",&x,&y,&seed,&base);
18 for(int j=lst+1;j<=x;j++){
19 t[j]=rnd()%2+1;
20 a[j]=rnd()%y+1;
21 }
22 lst=x;
23 }
24 for(int i=1;i<=n;i++)tot[t[i]]+=a[i];
25 if (tot[1]!=tot[2]){
26 if (tot[1]<tot[2])p=1;
27 else p=2;
28 }
29 else p=t[1];
30 if (p!=t[1]){
31 a[1]--;
32 ans[1]++;
33 }
34 for(int i=1;i<=n;i++)
35 if (t[i]==p){
36 s+=a[i];
37 ans[i]+=a[i];
38 a[i]=0;
39 }
40 else{
41 int x=min((ll)a[i],s);
42 ans[i]+=x;
43 s-=x;
44 a[i]-=x;
45 }
46 for(int i=1;i<=n;i++)
47 if (t[i]==p){
48 s+=a[i];
49 ans[i]+=a[i];
50 a[i]=0;
51 }
52 else{
53 int x=min((ll)a[i],s);
54 ans[i]+=x;
55 s-=x;
56 a[i]-=x;
57 }
58 ans[0]=1;
59 for(int i=1;i<=n;i++)ans[0]=((ans[i]^(1LL*i*i))+1)%mod*ans[0]%mod;
60 printf("%d",ans[0]);
61 }
[cf1495E]Qingshan and Daniel的更多相关文章
- Disposable microfluidic devices: fabrication, function, and application Gina S. Fiorini and Daniel T
Disposable microfluidic devices: fabrication, function, and application Gina S. Fiorini and Daniel T ...
- 1.1 NCE21 Daniel Mendoza
1.text translation Two hundred years ago, boxing matches were very popular in England. At that time/ ...
- 代码本色 用编程模拟自然系统 (Daniel Shiffman 著)
https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.js http://www.box2d.org http://www.jbox2d.org ...
- Bad Day -- Daniel Powter
Bad Day Bad Day (坏天气) 来自 Daniel Powter -- 2005年MTV欧洲音乐奖提名最佳新人, 出自专辑 ...
- lesson 21 Daniel Mendoza
lesson 21 Daniel Mendoza bare 赤裸的 :boxers fought with bare fists crude 天然的:crude sugar, crude oil 粗俗 ...
- Codeforces Round #597 (Div. 2) F. Daniel and Spring Cleaning 数位dp
F. Daniel and Spring Cleaning While doing some spring cleaning, Daniel found an old calculator that ...
- CF1245F: Daniel and Spring Cleaning
CF1245F: Daniel and Spring Cleaning 题意描述: 给定区间\([L,R]\),其中 \((0\leq L,R\leq 10^9)\),问在区间内有多少数对\((x,y ...
- 『BASH』——Learn BashScript from Daniel Robbins——[003]
ABSTRACT: Daniel Robbins is best known as the creator of Gentoo Linux and author of many IBM develop ...
- 『BASH』——Learn BashScript from Daniel Robbins——[001-002]
ABSTRACT: Daniel Robbins is best known as the creator of Gentoo Linux and author of many IBM develop ...
随机推荐
- 从零入门 Serverless | Knative 带来的极致 Serverless 体验
作者 | 冬岛 阿里巴巴高级技术专家 Serverless 公众号后台回复"knative",即可免费下载<Knative 云原生应用开发指南>电子书! 导读:Serv ...
- java语言程序设计与数据结构(基础篇)第四章答案
4.1 import java.util.Scanner; public class Welcome { public static void main(String[] args) { Scanne ...
- 题解 [HNOI2019]序列
题目传送门 题目大意 给出一个\(n\)个数的数列\(A_{1,2,...,n}\),求出一个单调不减的数列\(B_{1,2,...,n}\),使得\(\sum_{i=1}^{n}(A_i-B_i)^ ...
- 👊 Spring技术原理系列(7)带你看看那些可能你还不知道的Spring特性技巧哦!
前提介绍 本文主要介绍相关Spring框架的一些新特性问题机制,包含了一些特定注解方面的认识. @Lazy可以延迟依赖注入 @Lazy注解修饰在类层面! @Lazy @Service public c ...
- HttpServletResponse 入门
继承体系 功能: 设置响应消息 1. 设置响应行 格式:HTTP/1.1 200 ok 设置状态码:setStatus(int sc) 2. 设置响应头:setHeader(String name, ...
- Redis 高阶数据类型重温
今天这个专题接着上一篇 Redis 的基本数据类型 继续讲解剩下的高阶数据类型:BitMap.HyperLogLog 和 GEO hash.这些数据结构的底层也都是基于我们前面说的 5 种 基本类型, ...
- Noip模拟13 2021.7.13:再刚题,就剁手&&生日祭
T1 工业题 这波行列看反就非常尴尬.....口糊出所有正解想到的唯独行列看反全盘炸列(因为和T1斗智斗勇两个半小时...) 这题就是肯定是个O(n+m)的,那就往哪里想,a,b和前面的系数分开求,前 ...
- dfs初步模板解析
#include<stdio.h> int a[10],book[10],n; //这里还有需要注意的地方C语言全局变量默认为0 void dfs(int step){ //此时在第ste ...
- Hash算法:双重散列
双重散列是线性开型寻址散列(开放寻址法)中的冲突解决技术.双重散列使用在发生冲突时将第二个散列函数应用于键的想法. 此算法使用: (hash1(key) + i * hash2(key)) % TAB ...
- Docker 安装 MySQL8
1. 环境准备 创建挂载数据目录和配置文件 mkdir -p /mnt/mysql/data /etc/mysql/conf touch /etc/mysql/conf/my.cnf 2. 拉取镜像 ...