Gym - 101608G (尺取)

本文介绍了一个算法问题:给定一组正整数,找到最长的连续子序列,使得该子序列中所有数的按位或运算结果不超过给定阈值。文章通过示例详细解释了问题背景及解决方法。

https://vjudge.net/contest/208695#problem/G
Just days before the JCPC, your internet service went down. You decided to continue your training at the ACM club at your university. Sadly, you discovered that they have changed the WiFi password. On the router, the following question was mentioned, the answer is the WiFi password padded with zeros as needed.

A subarray [l, r] of an array A is defined as a sequence of consecutive elements Al, Al + 1, ..., Ar, the length of such subarray is r - l + 1. The bitwise OR of the subarray is defined as: Al OR Al + 1 OR ... OR Ar, where OR is the bitwise OR operation (check the notes for details).
Given an array A of n positive integers and an integer v, find the maximum length of a subarray such that the bitwise OR of its elements is less than or equal to v.

Input
The first line contains an integer T (1 ≤ T ≤ 128), where T is the number of test cases.
The first line of each test case contains two space-separated integers n and v (1 ≤ n ≤ 105) (1 ≤ v ≤ 3 × 105).
The second line contains n space-separated integers A1, A2, …, An (1 ≤ Ai ≤ 2 × 105), the elements of the array.
The sum of n overall test cases does not exceed 106.

题意:
给定 n n 个数,求有最长的连续 区间长度使得区间内数的按位或小于等于给定v

#include<bits/stdc++.h>
using namespace std;
#define N 200010
#define LL long long
int p[N][22];

int cnt[22];
void add(int &now,int i){
    cnt[i]++;
    if(cnt[i]==1)now+=(1<<i);
}
void dec(int &now,int i){
    cnt[i]--;
    if(cnt[i]==0)now-=(1<<i);
}
int main(){
    freopen("wifi.in","r",stdin);
    int T;scanf("%d",&T);
    while(T--){
        memset(cnt,0,sizeof(cnt));
        memset(p,0,sizeof(p));
        int n,v;scanf("%d%d",&n,&v);
        int x;
        int now=0;
        int l=1;
        int ans=0;
        for(int r=1;r<=n;++r){
            scanf("%d",&x);
            for(int i=0;i<=20;++i){
                if(x&(1<<i))p[r][i]++, add(now,i);
            }
            while(now>v){
                for(int i=0;i<=20;++i){
                    if(p[l][i])dec(now,i);
                }
                l++;
            }
            ans=max(ans,r-l+1);
        }
        cout<<ans<<endl;
    }
}
### Gym-Gazebo Library for Robotics Simulation and Reinforcement Learning The **gym-gazebo** library is designed as a comprehensive toolset for roboticists, integrating simulation environments, middleware systems like ROS or ROS 2, and advanced machine learning paradigms such as reinforcement learning into one cohesive framework[^1]. This combination allows researchers and developers to design, test, and refine behavioral algorithms for robots within simulated conditions before deploying them onto real-world hardware. #### Key Features of gym-gazebo - It leverages the power of Gazebo—a widely-used physics simulator—to provide realistic simulations of robot dynamics. - The integration with ROS/ROS 2 enables seamless communication between different components involved in both simulation and physical deployment scenarios. - By incorporating reinforcement learning methodologies, it facilitates training models through trial-and-error processes while optimizing performance metrics over time. An updated version called **Gym-Ignition**, introduced later by some contributors working along similar lines but using Ignition instead of classic GAZEBOSimulations offers reproducible experiments which are crucial when comparing results across studies involving deep reinforcement learning applications specifically tailored towards autonomous vehicles among other domains mentioned earlier under references four & five respectively.[^4] Here’s how you can install `gym-gazebo` via pip command typically used inside Python virtual environments: ```bash pip install gym-gazebo ``` For more customized installations depending upon specific versions required alongside compatible dependencies including particular releases associated either directly from source repositories hosted generally at GitHub pages maintained actively throughout recent years until now; refer official documentation links provided usually after each release announcement posts found easily searching terms related above citations given previously too!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值