fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp> // Common file
  3. #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
  4. using namespace std;
  5. typedef long long ll;
  6. typedef long double ld;
  7. typedef vector<int> vi;
  8. typedef vector<long long> vll;
  9. typedef vector<vector<int>> vvi;
  10. typedef vector<vll> vvll;
  11. typedef vector<pair<int, int>> vpi;
  12. typedef vector<vpi> vvpi;
  13. typedef pair<int, int> pi;
  14. typedef pair<ll, ll> pll;
  15. typedef vector<pll> vpll;
  16. const long long mod = 1000000007;
  17. #define MEM(a, b) memset(a, (b), sizeof(a))
  18. #define all(c) (c).begin(), (c).end()
  19. #define srt(c) sort(all(c))
  20. #define all_r(c) (c).rbegin(), (c).rend()
  21. #define reverse_sort(c) sort(all_r(c))
  22. #define sf(a) scanf("%d", &a)
  23. #define pf(a) printf("%d\n", a)
  24. #define unique(a) a.erase(unique(all(a)), a.end()) // ssseeesss would be ses
  25. #define pb push_back
  26. #define mp make_pair
  27. #define F first
  28. #define S second
  29. #define Check cout << "Done in " << clock() / CLOCKS_PER_SEC << " sec" << endl;
  30. #define FastRead ios_base::sync_with_stdio(false);
  31. using namespace __gnu_pbds;
  32. typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
  33.  
  34. // ================================== take ip/op like vector,pairs directly!==================================
  35. template<typename typC,typename typD> istream &operator>>(istream &cin,pair<typC,typD> &a) { return cin>>a.first>>a.second; }
  36. template<typename typC> istream &operator>>(istream &cin,vector<typC> &a) { for (auto &x:a) cin>>x; return cin; }
  37. template<typename typC,typename typD> ostream &operator<<(ostream &cout,const pair<typC,typD> &a) { return cout<<a.first<<' '<<a.second; }
  38. template<typename typC,typename typD> ostream &operator<<(ostream &cout,const vector<pair<typC,typD>> &a) { for (auto &x:a) cout<<x<<'\n'; return cout; }
  39. template<typename typC> ostream &operator<<(ostream &cout,const vector<typC> &a) { int n=a.size(); if (!n) return cout; cout<<a[0]; for (int i=1; i<n; i++) cout<<' '<<a[i]; return cout; }
  40. // ===================================END Of the input module ==========================================
  41.  
  42. void solve() {
  43. ll n,t;
  44. cin >> n>>t;
  45. vi v(n);
  46. cin >> v;
  47. //ordered_set m;
  48. ordered_set m;
  49. unordered_map<int,int> ma;
  50. for(int i=0;i<n;i++){
  51. ma[i+1]=v[i];
  52. m.insert(v[i]);
  53. }
  54. while(t--){
  55. char c;int x,y;
  56. cin >> c >> x >> y;
  57. if(c=='?'){
  58. int lessThanY=m.order_of_key(y+1);
  59. int lessThanX=m.order_of_key(x);
  60. cout<<lessThanY-lessThanX<<endl;
  61. }
  62. else{
  63. int toRemove=ma[x];
  64. //cout<<toRemove<<" hhhhh "<<*m.upper_bound(toRemove)<<endl;
  65. m.erase(m.upper_bound(toRemove));
  66. ma[x]=y;
  67. m.insert(y);
  68. }
  69. }
  70.  
  71. }
  72.  
  73. int main() {
  74. FastRead;
  75. int t = 1;
  76. while (t--) {
  77. solve();
  78. }
  79. return 0;
  80. }
Success #stdin #stdout 0.01s 5364KB
stdin
Standard input is empty
stdout
Standard output is empty