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. ES6新特性学习(一)

    一.什么是ES6 ECMAScript和JavaScript的关系 ECMAScript 6(以下简称ES6)是JavaScript语言的下一代标准,已经在2015年6月正式发布了.Mozilla公司 ...

  2. Edgware Feign hystrix-dashboard

    相关依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring ...

  3. @EnableEurekaClient源码分析

    @EnableEurekaClient注解,从源码的角度分析是如何work的 NetFlix Eureka client Eureka client 负责与Eureka Server 配合向外提供注册 ...

  4. angular数据绑定---js全局学习

    <!DOCTYPE html> <html ng-app> <head> <title>Simple app</title> </he ...

  5. JavaScript原型与继承(1)

    内容: 创建对象的几种模式以及创建的过程 原型链prototype的理解,以及prototype与 __proto__([[Prototype]])的关系 继承的几种实现 1.常见模式与原型链的理解 ...

  6. Tomcat debug模式下特别慢但是run正常处理方法

    转载自:http://blog.csdn.net/builderwfy/article/details/50785749 到网上查资料发现这是由eclipse和tomcat交互时,在debug模式启动 ...

  7. datatables的学习总结

    $(document).ready(function() { var oTable= $('#dataTables-example').DataTable({ // searching : false ...

  8. java 执行 class

    run.sh: #!/bin/bash CLASSPATH=. for jar in *.jar; do CLASSPATH=$CLASSPATH:$jardone CACHE_FILE=`pwd`/ ...

  9. poj 1962(并查集+带权更新)

    Corporative Network Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 3664   Accepted: 13 ...

  10. 赤峰项目目前的mysql配置项目

    #BEGIN CONFIG INFO #DESCR: 4GB RAM, InnoDB only, ACID, few connections, heavy queries #TYPE: SYSTEM ...