1000w的数组,一开始都是2^31-1,然后经过5*10^7次随机位置的随机修改,问你每次的全局最小值。

有效的随机修改的期望次数很少,只有当修改到的位置恰好是当前最小值的位置时才需要扫一下更新最小值。

分个块或者直接暴力都可以。

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int sz,l[10005],r[10005],sum,num[10000005];
unsigned int x0,x1,a,b,c,A[10000005],minv[10005];
unsigned int next() {
unsigned int t = x0 * a + x1 * b + c;
x0 = x1;
x1 = t;
return x0 >> 2;
}
int n,q;
int main(){
// freopen("i.in","r",stdin);
cin>>n>>q>>x0>>x1>>a>>b>>c;
for(int i=1;i<=n;++i){
A[i]=((unsigned int)1<<31)-1;
}
sz=sqrt(n);
for(sum=1;sum*sz<n;sum++)
{
l[sum]=(sum-1)*sz+1;
r[sum]=sum*sz;
for(int i=l[sum];i<=r[sum];i++)
num[i]=sum;
}
l[sum]=sz*(sum-1)+1;
r[sum]=n;
for(int i=l[sum];i<=r[sum];i++)
num[i]=sum;
for(int i=1;i<=sum;++i){
minv[i]=((unsigned int)1<<31)-1;
}
unsigned int nowans=((unsigned int)1<<31)-1;
unsigned int base=1;
unsigned int ans=0;
for(int i=1;i<=q;++i){
base*=(unsigned)10099;
unsigned int p=next()%(unsigned int)n;
unsigned int former=A[p+1];
A[p+1]=next();
int t=num[p+1];
if(former==minv[t]){
minv[t]=((unsigned int)1<<31)-1;
for(int i=l[t];i<=r[t];++i){
minv[t]=min(minv[t],A[i]);
}
}
else if(A[p+1]<minv[t]){
minv[t]=A[p+1];
}
if(former==nowans){
nowans=((unsigned int)1<<31)-1;
for(int i=1;i<=sum;++i){
nowans=min(nowans,minv[i]);
}
}
else if(A[p+1]<nowans){
nowans=A[p+1];
}
ans+=nowans*base;
}
cout<<ans<<endl;
return 0;
}

【分块】【暴力】XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Problem I. Rage Minimum Query的更多相关文章

  1. XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Problem D. Great Again

    题目: Problem D. Great AgainInput file: standard inputOutput file: standard outputTime limit: 2 second ...

  2. XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Problem K. Piecemaking

    题目:Problem K. PiecemakingInput file: standard inputOutput file: standard outputTime limit: 1 secondM ...

  3. XVII Open Cup named after E.V. Pankratiev. Grand Prix of America (NAIPC-2017)

    A. Pieces of Parentheses 将括号串排序,先处理会使左括号数增加的串,这里面先处理减少的值少的串:再处理会使左括号数减少的串,这里面先处理差值较大的串.确定顺序之后就可以DP了. ...

  4. XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Khamovniki Problem J Stairways解题报告(分块+维护凸壳)

    首先ORZ一发Claris聚聚的题解:http://www.cnblogs.com/clrs97/p/8689215.html,不然我可能没机会补过这道神题了. 这里写一个更详细的题解吧(我还是太菜了 ...

  5. XVIII Open Cup named after E.V. Pankratiev. Grand Prix of SPb

    A. Base $i - 1$ Notation 两个性质: $2=1100$ $122=0$ 利用这两条性质实现高精度加法即可. 时间复杂度$O(n)$. #include<stdio.h&g ...

  6. XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Siberia

    1. GUI 按题意判断即可. #include<stdio.h> #include<iostream> #include<string.h> #include&l ...

  7. XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Peterhof

    A. City Wall 找规律. #include<stdio.h> #include<iostream> #include<string.h> #include ...

  8. XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Khamovniki

    A. Ability Draft 记忆化搜索. #include<stdio.h> #include<iostream> #include<string.h> #i ...

  9. XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Korea

    A. Donut 扫描线+线段树. #include<cstdio> #include<algorithm> using namespace std; typedef long ...

随机推荐

  1. Coursera在线学习---第九节(1).异常数据检测(Anomaly Detection)

    一.如何构建Anomaly Detection模型? 二.如何评估Anomaly Detection系统? 1)将样本分为6:2:2比例 2)利用交叉验证集计算出F1值,可以用F1值选取概率阈值ξ,选 ...

  2. Python阶段复习 - part 4 - 用户登录程序

    简易版: #!/usr/bin/env python # _*_ coding:UTF-8 _*_ # __auth__:Dahlhin import sys userinfo = r'userinf ...

  3. (十九)git版本管理软件——搭建git服务器

    创建管理员git 为管理员用户添加sudo权限 生成管理员秘钥 设置管理员git提交账号和邮箱 下载安装gitolite 启动gitolite 添加项目版本库 添加项目成员 项目成员下载项目 gito ...

  4. [bugfix]copy属性参数将NSMutableArray变为NSArray类型

    问题:NSMutableArray 声明为 copy 属性参数后即使接受NSMutableArray变量依然为NSArray变量 测试: 属性申明为: 1 @property (nonatomic, ...

  5. spring restTemplate 用法

    发出get请求,方式一 String url = serverUrl+"/path/path?id={id}"; int i = restTemplate.getForObject ...

  6. HIbernate学习笔记2 之 主键生成方式

    一.hibernate主键生成方式: 1.常用方式:mysql:自增长生成主键(identity) <generator class="identity"> </ ...

  7. Guava Cache 使用笔记

    https://www.cnblogs.com/parryyang/p/5777019.html https://www.cnblogs.com/shoren/p/guava_cache.html J ...

  8. angularJS的MVC的用法

    1.前端MVC: M:Model,数据库 V:HTML页面 C:Control控制器 比较很有名的前端MVC框架:ExtJs 2.angularJS的MVC框架搭建 index.html代码如下: & ...

  9. Sql Server递归查询(转)

    有如下数据表 假如我们要查询ID为003的数据的所有子节点我们可以使用CTE 递归查询完成... if OBJECT_ID('tb','N') is not null drop table tb; c ...

  10. Mac安装Maven

    1.从官网(https://maven.apache.org/download.cgi)下载 Maven 并解压. 2.配置环境 .  vim ~/.bash_profile export MAVEN ...