Shopping Gym
来源:互联网 发布:无线摄像头破解软件 编辑:程序博客网 时间:2024/06/04 18:57
参考https://vjudge.net/solution/10900093
心得: 原来二分还能这样对与区间用
#include<bits/stdc++.h>#include<iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define sf scanf#define pf printf#define mem(a,b) memset(a,b,sizeof(a));#define rep(i,a,b) for(int i=(a);i<=(b);++i)#define MP make_pair#define ULL unsigned long long#define LL long long#define inf 0x3f3f3f3f#define md ((ll+rr)>>1)#define ls (i<<1)#define rs (ls|1)#define eps 1e-5#define ree freopen("in.txt","r",stdin);#define bug pf("----------------");#define N 200050#define M 20020#define INF 1e9int n,q;LL a[N];LL dp[N][30];int mm[N];void init(){ mm[0]=-1; for(int i=1;i<=n;++i){ mm[i]=((i&(i-1))==0)?mm[i-1]+1:mm[i-1]; //上面那行原本是这样的 mm[i]=(i&(i-1)==0)?mm[i-1]+1:mm[i-1]; 找了很久的错 dp[i][0]=a[i]; } for(int j=1;j<=mm[n];++j) for(int i=1;i+(1<<j)-1<=n;++i) dp[i][j]=min(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);}LL rmq(int x,int y){ int k=mm[y-x+1]; return min(dp[x][k],dp[y-(1<<k)+1][k]);}int main(){ //ree sf("%d%d",&n,&q); for(int i=1;i<=n;++i)sf("%lld",&a[i]); init(); while(q--){ LL x; int l,r; sf("%lld%d%d",&x,&l,&r); int now=l; while(x&&now<=r){ int lb=now-1,ub=r; while(ub>lb+1){ int mid=(lb+ub)>>1; if(rmq(now,mid)<=x)ub=mid; else lb=mid; } x%=a[ub]; now=ub+1; } pf("%lld\n",x); }}
阅读全文
0 0
- Shopping Gym
- Gym 100803C — Shopping
- Gym 101201J Shopping(RMQ +二分 )
- gym 101201 fast-en J Shopping
- Codeforces Gym 100803C Shopping 贪心好题
- shopping
- shopping
- Shopping
- Shopping
- shopping
- Shopping
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- Gym
- iOS11和iOS10有什么区别?
- poj 3264 Balanced Lineup
- tensorflow编程: Math
- srpingMVC02注解
- 【机器学习笔记】Locally Weighted Regression (Loess)
- Shopping Gym
- 我与博客的故事之纪念
- 二分查找算法原理及其java循环实现
- os模块和fileinput模块的用法解析
- 归并分治找最大连续子序列
- centos下网络配置四种方式
- MySQL-InnoDB索引
- < 笔记 > Python
- php