选择其中卡片总数较少的一类,当相同时选择$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的更多相关文章

  1. 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 ...

  2. 1.1 NCE21 Daniel Mendoza

    1.text translation Two hundred years ago, boxing matches were very popular in England. At that time/ ...

  3. 代码本色 用编程模拟自然系统 (Daniel Shiffman 著)

    https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.js http://www.box2d.org http://www.jbox2d.org ...

  4. Bad Day -- Daniel Powter

                                     Bad Day Bad Day (坏天气) 来自 Daniel Powter -- 2005年MTV欧洲音乐奖提名最佳新人, 出自专辑 ...

  5. lesson 21 Daniel Mendoza

    lesson 21 Daniel Mendoza bare 赤裸的 :boxers fought with bare fists crude 天然的:crude sugar, crude oil 粗俗 ...

  6. 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 ...

  7. CF1245F: Daniel and Spring Cleaning

    CF1245F: Daniel and Spring Cleaning 题意描述: 给定区间\([L,R]\),其中 \((0\leq L,R\leq 10^9)\),问在区间内有多少数对\((x,y ...

  8. 『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 ...

  9. 『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 ...

随机推荐

  1. 新一代容器平台ACK Anywhere,来了

    5G.AR.AIoT 等场景在推动新一代云架构的演进,而容器重塑了云的使用方式. 近日,阿里云容器服务全面升级为ACK Anywhere,让企业在任何需要云的地方,都能获得一致的容器基础设施能力. 早 ...

  2. Python异常代码含义对照表

    Python常见的异常提示及含义对照表如下: 异常名称 描述 BaseException 所有异常的基类 SystemExit 解释器请求退出 KeyboardInterrupt 用户中断执行(通常是 ...

  3. windows中抓包命令,以及保存为多个文件的方法

    本文主要介绍windows中抓包命令,以及保存为多个文件的方法 说一说保存为多个文件存储数据包这个问题的由来,一般如果长时间抓包,有可能需要等上几个小时,因为这个时候抓包的内容都是存放在内存中的,几个 ...

  4. 构建idea父工程

    构建idea父工程 首先通过idea新建一个Maven项目: 选择本地Maven版本: 工程名称: 选择字符编码:utf-8 file -> Settings -> Editor -> ...

  5. 查询windows日志

    系统日志可以用来查看系统的一些信息,比如警告.错误.验证.开关机等. 打开系统日志 按下快捷键win+R,输入eventvwr.exe,并点击确定 查询开关机记录 点击左侧Windows日志-> ...

  6. The Data Way Vol.5|这里有一场资本与开源的 battle

    关于「The Data Way」 「The Data Way」是由 SphereEx 公司出品的一档播客节目.这里有开源.数据.技术的故事,同时我们关注开发者的工作日常,也讨论开发者的生活日常:我们聚 ...

  7. 生成base64图片验证码

    github.com/mojocn/base64Captcha func GetCaptcha(c *gin.Context){ driver := base64Captcha.NewDriverDi ...

  8. NOIP&CSP 考前 Dev-cpp 的选项问题和考试心态

    (进入考场后您将获得一个崭新的 \(Dev-cpp\),没有中文,没有编译选项,没有缺省源:我还将获得一个崭新的脑子,没有心态,没有智商,没有调试能力--) 中文 \[Step1 \] \[Step2 ...

  9. 一时兴起,用python抓了一下美女图片。实现简单。附上实现代码,可以交流。

    """1.定义目标网址 网址2.数据定位 照片3.数据匹配 标签4.数据下载 下载"""import requestsfrom lxml i ...

  10. js--typeof 和 instanceof 判断数据类型的区别及开发中的使用

    前言 日常的开发中,我们经常会遇到判断一个变量的数据类型或者该变量是否为空值的情况,你是如何去选择判断类型的操作符的?本文来总结记录一下我们开发人员必须掌握的关于 typeof 和 instanceo ...