fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. #define pb push_back
  5. #define F first
  6. #define S second
  7. #define all(v) v.begin(),v.end()
  8. #define P pair
  9. #define V vector
  10. const long long MOD = 1000000007; // 1e9 + 7
  11.  
  12. long long mod(long long a, long long b) {
  13. return (a % b + b) % b;
  14. }
  15. void file(){
  16. freopen("input.txt.txt","r",stdin);
  17. freopen("output.txt.txt","w",stdout);
  18. }
  19. int maxer(int a,int b,int c){
  20. return max(a,max(b,c));
  21. }
  22. void setio(string s) {
  23. freopen((s + ".in").c_str(), "r", stdin);
  24. freopen((s + ".out").c_str(), "w", stdout);
  25. }
  26.  
  27. bool issorted(int n,int A[]){
  28. for(int i=0;i<n-1;i++){
  29. if(A[i+1]<A[i])
  30. return false;
  31. }
  32. return true;
  33. }
  34. void dfs(int x,vector<int>graph[],vector<bool>&visited,vector<int>&vp) {
  35. if (visited[x])return;
  36. visited[x] = true;
  37. vp.pb(x);
  38. for (auto u: graph[x])
  39. dfs(u, graph, visited, vp);
  40. }
  41. vector<ll>divisors(ll n){
  42. vector<ll>ans;
  43. for(ll i=1;i*i<=n;i++){
  44. if(i*i==n){
  45. ans.pb(i);
  46. continue;
  47. }
  48. if(n%i==0){
  49. ans.pb(i);
  50. ans.pb(n/i);
  51. }
  52. }
  53. return ans;
  54. }
  55. bool check(ll m,const ll A[],ll k){
  56. return k>=A[m];
  57. }
  58. struct node{
  59. ll max_seg;
  60. ll max_pref;
  61. ll max_suff;
  62. ll sum;
  63. };
  64. struct segtree{
  65. int size;
  66. V<int>sums;
  67. int value(int i){
  68. return sums[i+size];
  69. }
  70. void init(int n){
  71. size=1;
  72. while(size<n)size*=2;
  73. sums.assign(2*size,0LL);
  74. }
  75. void set(int i,int v){
  76. i+=size;
  77. sums[i]=v;
  78. for(i/=2;i>=1;i/=2){
  79. sums[i]=sums[2*i]+sums[2*i+1];
  80. }
  81. }
  82. int result(int k){
  83. int search=1;
  84. while(search<size){
  85. int s1=sums[search*2];
  86. if(s1>=k+1)
  87. search*=2;
  88. else
  89. search=search*2+1;
  90. }
  91. return search-size;
  92. }
  93. };
  94. void solve(){
  95. int n,q;
  96. cin>>n>>q;
  97. segtree st;
  98. st.init(n);
  99. for(int i=0;i<n;i++){
  100. int x;
  101. cin>>x;
  102. st.set(i,x);
  103. }
  104. while(q--){
  105. int t;
  106. cin>>t;
  107. if(t==1){
  108. int index;
  109. cin>>index;
  110. if(st.value(index)==1)
  111. st.set(index,0);
  112. else
  113. st.set(index,1);
  114. }
  115. else{
  116. int k;
  117. cin>>k;
  118. cout<<st.result(k)<<endl;
  119. }
  120. }
  121. }
  122.  
  123.  
  124. int main(){
  125. //file();
  126. solve();
  127. return 0;
  128. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty