fork download
  1. /* Priyansh Agarwal*/
  2. #include<bits/stdc++.h>
  3. #include<algorithm>
  4. #include<unordered_map>
  5. #include<vector>
  6. #include<unordered_set>
  7. #include<set>
  8. #include<map>
  9. #include<queue>
  10. #include<stack>
  11. #include<map>
  12. using namespace std;
  13. #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
  14. #define MOD 1000000007
  15. #define MOD1 998244353
  16. #define nline "\n"
  17. #define pb push_back
  18. #define mp make_pair
  19. #define ff first
  20. #define ss second
  21. #define PI 3.141592653589793238462
  22. #define debug(x) cout << #x << " " << x <<endl;
  23. #define set_bits __builtin_popcount
  24. typedef long long ll;
  25. typedef unsigned long long ull;
  26. /*---------------------------------------------------------------------------------------------------------------------------*/
  27. ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
  28. ll expo(ll a, ll b, ll mod)
  29. {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
  30. vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
  31. void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size 3
  32. ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
  33. ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
  34. bool revsort(ll a, ll b) {return a > b;}
  35. void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
  36. ll combination(ll n, ll r, ll m, ll* fact) {ll val1 = fact[n]; ll val2 = mminvprime(fact[r], m); ll val3 = mminvprime(fact[n - r], m); return ((val1 * val2) % m * val3) % m;}
  37. /*--------------------------------------------------------------------------------------------------------------------------*/
  38. int bit[10000005];
  39. int limit = 10000004;
  40. int arr[200005];
  41. map<int, int> m;
  42. void update(int start, int limit, int value)
  43. {
  44. for (; start <= limit; start += start & (-start))
  45. bit[start] += value;
  46. }
  47. int query(int start)
  48. {
  49. int sum = 0;
  50. for (; start > 0; start -= start & (-start))
  51. sum += bit[start];
  52. return sum;
  53. }
  54. int helper(int value)
  55. {
  56. int x = value / 100;
  57. int ans = 0;
  58. if (x != 0)
  59. ans += query(x);
  60. int value1 = x * 100;
  61. while (value1 <= value)
  62. {
  63. ans += m[value1];
  64. value1++;
  65. }
  66. return ans;
  67. }
  68. int main()
  69. {
  70. fastio();
  71. #ifndef ONLINE_JUDGE
  72. freopen("Inp.txt", "r", stdin);
  73. freopen("Output.txt", "w", stdout);
  74. freopen("Error.txt", "w", stderr);
  75. #endif
  76. for (int i = 0; i <= 10000004; i++)
  77. bit[i] = 0;
  78. int n, q;
  79. cin >> n >> q;
  80. for (int i = 0; i < n; i++)
  81. {
  82. cin >> arr[i];
  83. update(arr[i] / 100 + 1, limit, 1);
  84. m[arr[i]]++;
  85. }
  86. while (q--)
  87. {
  88. char ch;
  89. cin >> ch;
  90. if (ch == '!')
  91. {
  92. int k;
  93. int value;
  94. cin >> k >> value;
  95. k--;
  96. update(arr[k] / 100 + 1, limit, -1);
  97. update(value / 100 + 1, limit, 1);
  98. m[arr[k]]--;
  99. arr[k] = value;
  100. m[arr[k]]++;
  101. }
  102. else
  103. {
  104. int a, b;
  105. cin >> a >> b;
  106. ll ans1 = helper(b);
  107. ll ans2 = helper(a - 1);
  108. cout << ans1 - ans2 << "\n";
  109. }
  110. }
  111. return 0;
  112. }
  113.  
Success #stdin #stdout 0.01s 42592KB
stdin
3 3
1 1000000000 10000
? 1 1000000000
? 1 1000000
! 1 2
stdout
3
2