Tunnel Warfare POJ - 2892(SET)

本文介绍了一个模拟抗日战争期间地道战的算法模型。该模型通过一系列输入事件(如村庄被破坏、重建或查询连接状态),利用数据结构高效地计算并输出各村庄间的连接状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Except the two at the ends, every village was directly connected with two neighboring ones.

Frequently the invaders launched attack on some of the villages and destroyed the parts of tunnels in them. The Eighth Route Army commanders requested the latest connection state of the tunnels and villages. If some villages are severely isolated, restoration of connection must be done immediately!

Input
The first line of the input contains two positive integers n and m (n, m ≤ 50,000) indicating the number of villages and events. Each of the next m lines describes an event.

There are three different events described in different format shown below:

D x: The x-th village was destroyed.
Q x: The Army commands requested the number of villages that x-th village was directly or indirectly connected with including itself.
R: The village destroyed last was rebuilt.
Output
Output the answer to each of the Army commanders’ request in order on a separate line.

Sample Input
7 9
D 3
D 6
D 5
Q 4
Q 5
R
Q 4
R
Q 4
Sample Output
1
0
2
4
Hint
An illustration of the sample input:

  OOOOOOO

D 3 OOXOOOO

D 6 OOXOOXO

D 5 OOXOXXO

R OOXOOXO

R OOXOOOO


查询每个点的连通数即与他相连的O的数量+1,只需要找到其往左第一个X和往右第一个X,然后求差值-1,注意边界。用set处理很方便。

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<map>
#include<set>
#include<vector>
using namespace std;
bool p[50005];
int d[50005];
int n,m;
int dnum;
set<int> s;
int main(){
    scanf("%d%d",&n,&m);
    dnum=0;
    string str;
    int num;
    for(int i=1;i<=n;i++){p[i]=1;}
    for(int i=0;i<m;i++){
        cin>>str;
        if(str=="D"){scanf("%d",&num);
            d[dnum++]=num;
            s.insert(num);
            p[num]=0;
        }
        else if(str=="Q"){
            scanf("%d",&num);
            if(p[num]==0){printf("0\n");}
            else{
                set<int>::iterator it=s.lower_bound(num);
                int ans=n+1;
                if(it!=s.end()){ans=(*it);}
                if(it!=s.begin()){
                    it--;
                    ans-=(*it);
                }
                ans--;
                printf("%d\n",ans);
            }
        }
        else{
            dnum--;
            p[d[dnum]]=1;
            s.erase(s.find(d[dnum]));
        }
    }
return 0;
}
<think>我们正在处理用户关于使用Helm安装Cilium v1.14.0时缺少参数的问题。根据用户提供的错误信息和引用内容,我们可以推断用户可能在使用较新版本的Cilium(如v1.15)时遇到了问题,但用户现在指定要安装的是v1.14.0。然而,用户的问题描述中提到了一个错误,该错误指出在v1.15中移除了tunnel参数,因此我们需要确保在安装v1.14.0时正确设置参数以避免将来升级的问题。 根据用户提供的引用[1],我们可以使用cilium-cli来获取之前的配置并重新安装。但是,用户现在的问题是使用Helm安装,并且询问缺少哪些参数。 用户之前遇到的错误是: Error: INSTALLATION FAILED: execution error at (cilium/templates/validate.yaml:41:5): tunnel was deprecated in v1.14 and has been removed in v1.15. 这个错误出现在v1.15的安装中,但用户现在指定安装v1.14.0。因此,在v1.14.0中,tunnel参数仍然可用,但已被标记为废弃。所以,在安装v1.14.0时,我们可以继续使用tunnel参数,但建议开始迁移到新的参数。 然而,用户的问题是:“Helm install Cilium cilium/cilium version 1.14.0 namespace kube-system missing parameters”,即在使用Helm安装Cilium 1.14.0时缺少哪些参数? 实际上,Cilium的安装需要一些必要的配置参数,这些参数取决于用户的集群环境。常见的必要参数包括: 1. 网络相关参数:如Pod CIDR、Service CIDR等。 2. 路由模式:tunnel(vxlan或geneve)或直接路由(native)等。 3. 其他特性:如kube-proxy替换、负载均衡模式等。 但是,根据错误信息,我们知道在v1.14中tunnel参数已被废弃,因此即使我们使用v1.14,也应该避免使用tunnel参数,而使用新的参数配置。 在v1.14中,新的参数是: - `routingMode`:替代tunnel参数,可选值有`tunnel`、`native`、`disabled`(其中`disabled`用于BPF主机路由模式)。 - `ipv4NativeRoutingCIDR`:当使用`routingMode=native`时,必须设置此参数为集群的Pod CIDR。 因此,在安装v1.14.0时,我们应使用新的参数,以避免将来升级到v1.15时出现问题。 所以,用户在使用Helm安装v1.14.0时,应该使用新的参数,而不是废弃的tunnel参数。 下面是一个示例的Helm命令,使用新的参数安装Cilium v1.14.0: ```bash helm install cilium cilium/cilium --version 1.14.0 \ --namespace kube-system \ --set routingMode=native \ --set ipv4NativeRoutingCIDR=10.0.0.0/8 # 请替换为你的集群Pod CIDR ``` 或者使用values文件: ```yaml # values.yaml routingMode: native ipv4NativeRoutingCIDR: 10.0.0.0/8 ``` 然后运行: ```bash helm install cilium cilium/cilium --version 1.14.0 -f values.yaml -n kube-system ``` 注意:`ipv4NativeRoutingCIDR`必须设置为集群的Pod CIDR,这样Cilium才能知道哪些IP是本地路由的。 如果用户之前使用的是tunnel模式,那么可以这样设置: ```yaml routingMode: tunnel tunnelProtocol: vxlan # 或者geneve ``` 另外,根据引用[1],如果用户之前已经安装过Cilium,可以通过获取保存的配置来重新安装。但是,用户现在的问题是关于缺少参数,所以我们需要确保在安装时提供必要的参数。 总结:在安装Cilium v1.14.0时,必须设置`routingMode`和(如果是native模式)`ipv4NativeRoutingCIDR`参数,以替代废弃的`tunnel`参数。 现在,我们来回答用户的问题:在使用Helm安装Cilium v1.14.0时,缺少的参数是`routingMode`和(如果使用native模式)`ipv4NativeRoutingCIDR`。用户需要根据自己集群的网络模式选择设置这些参数。 同时,我们也可以参考引用[3]中关于Cilium安全可见性的内容,但这不是安装所必需的。 因此,回答如下:</think>### 使用 Helm 安装 Cilium v1.14.0 的必要参数配置 在安装 Cilium v1.14.0 时,核心参数已从 `tunnel` 迁移到新的路由模式配置。以下是完整参数指南(基于 Cilium 官方文档和最佳实践[^1][^3]): #### 1. **核心网络参数(必须配置)** ```yaml # 路由模式 (替代废弃的 tunnel 参数) routingMode: native # 可选值: native, tunnel, disabled # 当使用 native 模式时必须设置 ipv4NativeRoutingCIDR: "10.0.0.0/8" # 替换为您的集群 Pod CIDR # IPAM 模式 ipam: mode: kubernetes # 或 cluster-pool, azure, etc ``` #### 2. **完整 Helm 安装命令** ```bash helm install cilium cilium/cilium --version 1.14.0 \ --namespace kube-system \ --set routingMode=native \ --set ipv4NativeRoutingCIDR="10.0.0.0/8" \ --set ipam.mode=kubernetes \ --set kubeProxyReplacement=strict \ --set bpf.masquerade=true ``` #### 3. **关键参数说明表 | 参数 | 必需 | 默认值 | 说明 | |------|------|--------|------| | **`routingMode`** | 是 | - | 替换废弃的 `tunnel` 参数,定义路由机制 | | **`ipv4NativeRoutingCIDR`** | 当 `routingMode=native` | - | 集群的 Pod IP CIDR 范围 | | `ipam.mode` | 是 | `cluster-pool` | IP 地址分配机制 | | `kubeProxyReplacement` | 推荐 | `disabled` | 启用 eBPF 替代 kube-proxy | | `bpf.masquerade` | 推荐 | `false` | 启用 IP 伪装 | #### 4. **验证配置保存(升级时关键步骤) ```bash # 获取历史配置(如存在) kubectl -n kube-system get secret/cilium-cli-helm-values -o yaml > cilium-values.yaml # 使用保存的配置安装 cilium install \ --helm-values cilium-values.yaml \ --version v1.14.0 \ --context kubernetes-admin@kubernetes ``` #### 5. **服务账户配置(可选但推荐) ```yaml # 创建服务账户(用于安全策略) apiVersion: v1 kind: ServiceAccount metadata: name: cilium-sa namespace: kube-system ``` ```bash kubectl create serviceaccount cilium-sa -n kube-system ``` > **重要提示**:在 v1.14 中 `tunnel` 参数已被废弃,必须使用 `routingMode` 替代。安装后可通过 `cilium status` 验证路由模式[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值