【分块】【暴力】XVII Open Cup named after E.V. Pankratiev Grand Prix of Moscow Workshops, Sunday, April 23, 2017 Problem I. Rage Minimum Query
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的更多相关文章
- 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 ...
- 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 ...
- XVII Open Cup named after E.V. Pankratiev. Grand Prix of America (NAIPC-2017)
A. Pieces of Parentheses 将括号串排序,先处理会使左括号数增加的串,这里面先处理减少的值少的串:再处理会使左括号数减少的串,这里面先处理差值较大的串.确定顺序之后就可以DP了. ...
- 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,不然我可能没机会补过这道神题了. 这里写一个更详细的题解吧(我还是太菜了 ...
- 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 ...
- XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Siberia
1. GUI 按题意判断即可. #include<stdio.h> #include<iostream> #include<string.h> #include&l ...
- XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Peterhof
A. City Wall 找规律. #include<stdio.h> #include<iostream> #include<string.h> #include ...
- XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Khamovniki
A. Ability Draft 记忆化搜索. #include<stdio.h> #include<iostream> #include<string.h> #i ...
- XVIII Open Cup named after E.V. Pankratiev. Grand Prix of Korea
A. Donut 扫描线+线段树. #include<cstdio> #include<algorithm> using namespace std; typedef long ...
随机推荐
- windows7_常用操作终端操作
查看环境变量:set 添加环境变量:set aa = 88 删除环境变量:set aa = 查看ip配置:ipconfig 查看全局环境变量配置:path 查看当前目录文件:dir 进入E盘:E: 进 ...
- Part2-HttpClient官方教程-Chapter7-高级主题(Advanced topics) (HTTP Caching)
原文链接 7.1 自定义客户端连接 在某些情况下,为了能够处理非标准的.不兼容的行为,可能需要自定义HTTP消息通过网络传输的方式,而不是使用HTTP参数.例如,对于web爬虫,可能有必要迫使Http ...
- 网络协议之HTTP协议
HTTP协议详解(真的很经典) 转自:http://blog.csdn.net/gueter/archive/2007/03/08/1524447.aspx Author :Jeffrey 引言 HT ...
- mysql之安装和配置(一)
环境 oracle linux7.3 数据库:MySQL-5.7.20 mysql的安装 先安装依赖的插件 yum install libaio 去官网下载mysql-5.7.20的tar.gz包: ...
- sunos kernel src
https://github.com/eocallaghan/AuroraUX-SunOS https://github.com/zoyanhui/coroutine-libtask https:// ...
- 【模板】BZOJ 3781: 小B的询问 莫队算法
http://www.lydsy.com/JudgeOnline/problem.php?id=3781 N个数的序列,每次询问区间中每种数字出现次数的平方和,可以离线. 丢模板: #include ...
- c json实战引擎五 , 优化重构
引言 scjson是一个小巧的纯c跨平台小巧引擎. 适用于替换老的cJSON引擎的场景. 数据结构和代码布局做了大量改进.优势体现在以下几个方面: 1) 跨平台 (window 10 + VS2017 ...
- java中的i++与++i有什么区别?
刚开始接触时,做了一些小测试,还以为这两个没有什么区别. public class OperatorDemo { public static void main(String[] args){ int ...
- python 字典value排序
#!/usr/bin/env python#coding:utf-8s = {“a”:1,”b”:3,”c”:2} print sorted(s.iteritems(),key=lambda t:t[ ...
- LeetCode解题报告—— Trapping Rain Water
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...