[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 ...
随机推荐
- 题解 CF736D Permutations
link Description 现在,你有一个二分图,点数为 \(2n\). 已知这个二分图的完备匹配的个数是奇数. 现在你要知道,删除每条边后,完备匹配个数是奇数还是偶数. \(1\le n\le ...
- Java(24)常用API三
作者:季沐测试笔记 原文地址:https://www.cnblogs.com/testero/p/15228417.html 博客主页:https://www.cnblogs.com/testero ...
- Bootstrap移动端导航(简易)
效果 在线查看 代码少,都在HTML里 <!DOCTYPE html> <html lang="en"> <head> <meta cha ...
- Java:ArrayList类小记
Java:ArrayList类小记 对 Java 中的 ArrayList类,做一个微不足道的小小小小记 概述 java.util.ArrayList 是大小可变的数组的实现,存储在内的数据称为元素. ...
- Github Actions 实践
Github Actions 实践 Github Actions 是 Github 的持续集成服务,通过在 repo 发生特定的行为时执行指定的命令实现自动测试.自动部署等功能. 基本术语 workf ...
- the Agiles Scrum Meeting 6
会议时间:2020.4.14 20:00 1.每个人的工作 今天已完成的工作 增量组:开发广播正文展开收起功能 issues:增量组:广播正文展开收起功能实现 完善组:修复冲刺部分的bug issue ...
- 轻量级 Java 基础开发框架,Solon & Solon Cloud 1.5.52 发布
Solon 已有120个生态扩展插件,此次更新主要为细节打磨: 插件 mybatis-solon-plugin 增加 mappers 单行配置支持 之前的多行模式: mybatis.db1: type ...
- 《HelloGitHub》第 67 期
兴趣是最好的老师,HelloGitHub 让你对编程感兴趣! 简介 分享 GitHub 上有趣.入门级的开源项目. https://github.com/521xueweihan/HelloGitHu ...
- 方阵里面的dp
打了一场luogu的信心赛,惊讶地发现我不会T2,感觉像这样在矩阵里面的dp看起来很套路的样子,但是仔细想想还是有很多需要注意的细节. 又想到之前貌似也考过一些类似的题目 然而我并没有改 ,于是打算补 ...
- 2021.7.29考试总结[NOIP模拟27]
T1 牛半仙的妹子图 做法挺多的,可以最小生成树或者最短路,复杂度O(cq),c是颜色数. 我考场上想到了原来做过的一道题影子,就用了并查集,把边权排序后一个个插入,记录权值的前缀和,复杂度mlogm ...