fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long int lli;
  4. /*
  5. #include <chrono>
  6. using namespace std::chrono;
  7. #include <boost/multiprecision/cpp_int.hpp>
  8. using namespace boost::multiprecision;*/
  9. #include <ext/pb_ds/assoc_container.hpp>
  10. #include <ext/pb_ds/tree_policy.hpp>
  11. using namespace __gnu_pbds;
  12. #define ordered_set tree<pair<lli,lli>, null_type,less<pair<lli,lli>>, rb_tree_tag,tree_order_statistics_node_update>
  13.  
  14. #define endl "\n"
  15. #define pb push_back
  16. const lli mod=1e9+7;
  17. const lli mod1=998244353;
  18. #define fir first
  19. #define sec second
  20. #define plli pair<lli,lli>
  21. /*
  22. lli power(lli a, lli b) {
  23.   lli res = 1;
  24.   while (b > 0) {
  25.   if (b & 1)
  26.   res = res * a;
  27.   a = a * a;
  28.   b >>= 1;
  29.   }
  30.   return res;
  31. }
  32. lli powermod(lli a, lli b)
  33. {
  34.   lli res = 1;
  35.   while (b > 0) {
  36.   if (b & 1)
  37.   res = ((res%mod)*(a%mod))%mod;
  38.   a = (a * a)%mod;
  39.   b >>= 1;
  40.   }
  41.   return res;
  42. }
  43. */
  44. int main()
  45. {
  46. ios_base::sync_with_stdio(false);
  47. cin.tie(NULL);
  48. lli T;
  49. T=1;
  50. while(T--)
  51. {
  52. ordered_set s;
  53. lli n,q;
  54. cin>>n>>q;
  55. lli a[n+1],i;
  56. for(i=1;i<=n;i++)
  57. {
  58. cin>>a[i];
  59. s.insert({a[i],i});
  60. }
  61. char x;
  62. lli y,z;
  63. while(q--)
  64. {
  65. cin>>x>>y>>z;
  66. if(x=='!')
  67. {
  68. s.erase({a[y],y});
  69. a[y]=z;
  70. s.insert({a[y],y});
  71. }
  72. else
  73. {
  74. lli l=s.order_of_key({y,0});
  75. lli r=s.order_of_key({z,n+1});
  76. /*for(auto it:s)
  77.   cout<<it.fir<<" "<<it.sec<<"\n";*/
  78. cout<<r-l<<"\n";
  79. }
  80. }
  81.  
  82. }
  83. return 0;
  84. }
  85.  
  86.  
  87.  
  88.  
  89.  
Runtime error #stdin #stdout 0s 4828KB
stdin
Standard input is empty
stdout
Standard output is empty