【TMD模拟赛】黄金拼图 Cao

本文介绍了一种涉及离线推答案的算法实现,通过异或操作和质数判断完成特定任务。代码中包含了对输入数据的操作,如区间更新、查询等功能,并最终输出指定条件下的最小质数。

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

正解:Cao

据说这样的题是用来骗丛林生物上树的......

这样的题除了考观察力之外还.........我们发现他异或了opt,恩,就这样,用离线推答案.....

#include <cstdio>
#include <cstring>
#include <algorithm>
const int N=200020;
int n,k,m,s[N],last_l,last_r;
inline bool is(int x){
  for(int i=2;i*i<=x;++i)
    if(x%i==0)return false;
  return true;
}
int main(){
  scanf("%d%d%d",&n,&k,&m);
  for(int i=1;i<=n;++i)
    scanf("%d",&s[i]);
  int need=0;
  for(int i=1;i<=m;++i){
    int opt,x,y;
    scanf("%d%d%d",&opt,&x,&y);
    if(opt==1){last_l=x,last_r=y,need=1;continue;}
    if(opt==2){s[x]=y;continue;}
    if(opt&1){
      if(need)printf("%d\n",opt^2),need=0;
      s[x^(opt^2)]=y^(opt^2);
    }else{
      if(need)printf("%d\n",opt^1),need=0;
      last_l=x^(opt^1),last_r=y^(opt^1),need=1;
    }
  }
  if(need){
    std::sort(s+last_l,s+(last_r+1));
    for(int i=last_l;i<=last_r;++i)
      if(is(s[i])){
        --k;
        if(k==0){
          printf("%d\n",s[i]);
          break;
        }
      }
  }
  return 0;
}

 

转载于:https://www.cnblogs.com/TSHugh/p/7617753.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值