fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios_base::sync_with_stdio(0); cin.tie(0);
  6. int N, Q , cnt = 0;
  7. cin >> N >> Q;
  8. vector<int> v(N), dis, ans(Q);
  9. map<int,int> mp;
  10. for(int &x : v) cin >> x, mp[x];
  11. vector<array<int,4>> qry[N + 1];
  12.  
  13. for(int _Q = 0 ; _Q < Q; _Q++) {
  14. int l,r,x,y;
  15. cin >> l >> r >> x >> y;
  16. qry[l].push_back({r , x, y , _Q});
  17. }
  18.  
  19. for(auto &pr : mp) pr.second = ++cnt;
  20.  
  21. vector<vector<pair<int,int>>> fenwick(4 * N), fenwickCount(4 * N);
  22.  
  23. auto update = [&](int x,int r) {
  24. int v = x;
  25. int bcf = fenwick[x].size() ? fenwick[x].back() : 0 ;
  26. int bcfc = fenwickCount[x].size() ? fenwickCount[x].back() : 0 ;
  27. for(x = mp[x]; x < (N << 2) ; x += x & -x) fenwick[x].emplace_back(r , v + bcf)
  28. for(x = mp[v] ; x < (N << 2) ; x += x & -x) fenwickCount[x].emplace_back(r , bcfc + 1);
  29. };
  30.  
  31. auto query = [&](int topK,int r) {
  32. int res = 0,tot = 0, sum = 0;
  33. for(int lg = (1 << 20) ; lg ; lg >>= 1) {
  34. if(res + lg < (N << 2) and tot + fenwickCount[res ^ lg].get(r) <= topK) {
  35. res ^= lg;
  36. tot += fenwickCount[res];
  37. sum += fenwick[res];
  38. }
  39. }
  40. return sum;
  41.  
  42. };
  43.  
  44. /// query processing offline mode
  45. for(int i = N - 1 ; i >= 0; i--) {
  46. update(v[i]);
  47. for(auto &ar : qry[i]) {
  48. int l = i , r = ar[0] , x = ar[1] , y = ar[2] ;
  49. int idx = ar[3];
  50. // process query
  51.  
  52. ans[idx] = 0 ;///
  53. }
  54. }
  55.  
  56. // output
  57. for(int X : ans) cout << X << " ";
  58. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In lambda function:
prog.cpp:25:31: error: operands to ?: have different types ‘__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type’ {aka ‘std::pair<int, int>’} and ‘int’
   int bcf = fenwick[x].size() ? fenwick[x].back() : 0 ;
             ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:26:37: error: operands to ?: have different types ‘__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type’ {aka ‘std::pair<int, int>’} and ‘int’
   int bcfc = fenwickCount[x].size() ? fenwickCount[x].back() : 0 ;
              ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:27:82: error: expected ‘;’ before ‘for’
   for(x = mp[x]; x < (N << 2) ; x += x & -x) fenwick[x].emplace_back(r , v + bcf)
                                                                                  ^
                                                                                  ;
   for(x = mp[v] ; x < (N << 2) ; x += x & -x) fenwickCount[x].emplace_back(r , bcfc + 1);
   ~~~                                                                             
prog.cpp:28:45: error: expected ‘;’ before ‘)’ token
   for(x = mp[v] ; x < (N << 2) ; x += x & -x) fenwickCount[x].emplace_back(r , bcfc + 1);
                                             ^
                                             ;
prog.cpp: In lambda function:
prog.cpp:34:60: error: ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<int, int> > >, std::vector<std::pair<int, int> > >::value_type’ {aka ‘class std::vector<std::pair<int, int> >’} has no member named ‘get’
    if(res + lg < (N << 2) and tot + fenwickCount[res ^ lg].get(r) <= topK) {
                                                            ^~~
prog.cpp:36:9: error: no match for ‘operator+=’ (operand types are ‘int’ and ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<int, int> > >, std::vector<std::pair<int, int> > >::value_type’ {aka ‘std::vector<std::pair<int, int> >’})
     tot += fenwickCount[res];
prog.cpp:37:9: error: no match for ‘operator+=’ (operand types are ‘int’ and ‘__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<int, int> > >, std::vector<std::pair<int, int> > >::value_type’ {aka ‘std::vector<std::pair<int, int> >’})
     sum += fenwick[res];
prog.cpp: In function ‘int main()’:
prog.cpp:46:14: error: no match for call to ‘(main()::<lambda(int, int)>) (__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)’
   update(v[i]);
              ^
prog.cpp:23:31: note: candidate: ‘main()::<lambda(int, int)>’
  auto update = [&](int x,int r) {
                               ^
prog.cpp:23:31: note:   candidate expects 2 arguments, 1 provided
stdout
Standard output is empty