题目:
You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds:

1 x : Assign to ax the value 1−ax.
2 k : Print the k-th largest value of the array.
As a reminder, k-th largest value of the array b is defined as following:

Sort the array in the non-increasing order, return k-th element from it.
For example, the second largest element in array [0,1,0,1] is 1, as after sorting in non-increasing order it becomes [1,1,0,0], and the second element in this array is equal to 1.

Input
The first line contains two integers n and q (1≤n,q≤105) — the length of the given array and the number of queries.

The second line contains n integers a1,a2,a3,…,an (0≤ai≤1) — elements of the initial array.

Each of the following q lines contains two integers. The first integer is t (1≤t≤2) — the type of query.

If t=1 the second integer is x (1≤x≤n) — the position of the modified number. You have to assign to ax the value 1−ax.
If t=2 the second integer is k (1≤k≤n) — you need to print the k-th largest value of the array.
It’s guaranteed that there will be at least one query of the second type (satisfying t=2).

Output
For each query of the second type, print a single integer — the answer to the query.

Example
inputCopy
5 5
1 1 0 1 0
2 3
1 2
2 3
2 1
2 5
outputCopy
1
0
1
0
Note
Initially a=[1,1,0,1,0].

The first operation is printing the third largest value, which is 1.

The second operation is assigning a2 the value 0, a becomes [1,0,0,1,0].

The third operation is printing the third largest value, it is 0.

The fourth operation is printing the first largest value, it is 1.

The last operation is printing the fifth largest value, it is 0.
题解:

#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int main()
{int n,q;cin>>n>>q;int con=0;for(int i=1;i<=n;i++){scanf("%d",&a[i]);if(a[i]==1) con++;}while(q--){int t,x;cin>>t>>x;if(t==1) {a[x]=1-a[x];if(a[x]==0) con--;else con++;}else {if(x>con) cout<<"0"<<endl;else cout<<"1"<<endl;}}return 0;
}

K-th Largest Value相关推荐

  1. PyTorch搜索Tensor指定维度的前K大个(K小个)元素--------(torch.topk)命令参数详解及举例

    torch.topk 语法 torch.topk(input, k, dim=None, largest=True, sorted=True, *, out = None) 作用 返回输入tensor ...

  2. 寻找无序数组中第k大的数

    对于一个无序的数组,怎样找到其中第k大的数呢?下面总结几种方法. 1.直接排序法 使用常见的归并排序.堆排序等算法对数组进行排序,然后找到第k大的数.排序算法的时间复杂度为O(nlogn),所以算法总 ...

  3. MYSQL实现ORDER BY LIMIT的方法以及优先队列(堆排序)

    一.MYSQL中的LIMIT和ORACLE中的分页 在MYSQL官方文档中描述limit是在结果集中返回你需要的数据,它可以尽快的返回需要的行而不用管剩下的行, 在ORACLE中也有相关的语法比如 1 ...

  4. matlab pdist2函数官方详解

    pdist2 两组观测之间的成对距离 句法 D = pdist2(X,Y,Distance) D = pdist2(X,Y,Distance,DistParameter) D = pdist2(___ ...

  5. pytorch教程龙曲良21-25

    21合并与分割2 split 按照长度/单元长度拆分 c的shape是[2,32,8]aa,bb=c.split(1,dim=0)#操作单元是在0维度上操作,拆分单元长度是1aa,bb=c.split ...

  6. pytorch机器学习_机器学习— PyTorch

    pytorch机器学习 PyTorch : It is an open source machine learning library based on the Torch library (whic ...

  7. Python heapq模块

    Python heapq模块 heapq模块提供了如下几个函数: 函数 用法 heapq.heappush(heap, item) 把item添加到heap中(heap是一个列表) heapq.hea ...

  8. Transformers Assemble(PART IV)

    上一篇Transformers Assemble(PART III)重点在transformer位置信息的改进,这一集挑选了几篇都带有「Sparse」的标签,主要关注点在于transformer结构的 ...

  9. 基于FPGA的LSTM加速器设计(MNIST数据集为例)

    摘要 本文以MNIST手写数字识别任务为例,使用FPGA搭建了一个LSTM网络加速器,并选取MNIST数据集中的10张图片,通过vivado软件进行仿真验证.实验结果表明,本文设计的基于FPGA的LS ...

  10. 10万字C语言入门手册,历时三个月,详细的C语言教程终于出炉了,给你全新C语言入门体验

    C语言是一种非常流行的编程语言,它是许多现代编程语言的基础. 什么是计算机? 计算机是一种用于存储.处理.和输出数据的电子设备.它通过程序控制和数学算法来实现数据处理.计算机通过输入设备(如键盘.鼠标 ...

最新文章

  1. fuzz系列之libfuzzer
  2. 图像中添加二项式分布噪声
  3. 【数据结构与算法】之重复的DNA序列的算法求解
  4. 初学者万年历c语言源代码,C语言万年历的源程序
  5. POJ3889-Fractal Streets【分形,递归,分治】
  6. 面象对象设计6大原则之六:迪米特原则
  7. Shell 简单的java微服务jar包 -- 部署脚本
  8. mysql报错注入实战_手工注入——MySQL手工注入实战和分析
  9. 人脸识别(3)---静态人脸识别和动态人脸识别的区别
  10. [技巧]CSS的超级技巧大放送
  11. xml属于php还是js,xml是什么
  12. SQL Server数据库基础知识
  13. 古墓新手机器人_古墓新手任务攻略 - 玩家乐园 - 北大侠客行MUD论坛 - Powered by Discuz!...
  14. css+html+对错号,错号怎么打 接着点击符号/其他符号;
  15. surfacert能跑java么_不怕天气糟糕 出行全靠Surface来帮忙
  16. 如何在家打造一个沉浸式的家庭影院呢?
  17. Windows10 V2004 正式版发布
  18. html5 语音导航,百度地图个性化语音导航:用声音表心意
  19. 华为否认提前发年终奖 网传消息实为销售激励计划
  20. 查看oracle11g的企业管理器(OEM)

热门文章

  1. 新手上路参考驾驶手册 36计教你安全上路(收集)
  2. 3D设计软件中怎么快速建模?浩辰3D快速建模教程
  3. 独家丨Web3风向从NFTs吹向DAOs?一季度DAO发展回顾
  4. R语言之几大常见概率分布
  5. 阿里巴巴java规范
  6. android 内存至少一半,极客修:为什么iPhone比安卓内存小,却更流畅?
  7. The APR based Apache Tomcat Native library which allows optimal performance in production 问题的解决
  8. 网页直播源码IM即时通讯协议
  9. 爬虫爬取煎蛋网美女图片
  10. 未完成的IT路停在回车键 2014年末总结篇