/ SeriousOJ /

Record Detail

Compile Error

foo.cc:16:10: error: 'unordered_map' in namespace 'std::tr1' does not name a template type
   16 |     tr1::unordered_map <long long, int> mp; /// Change to int if only int in treap
      |          ^~~~~~~~~~~~~
foo.cc: In constructor 'Treap::Treap()':
foo.cc:21:20: error: 'mp' was not declared in this scope
   21 |         T.clear(), mp.clear();
      |                    ^~
foo.cc: In member function 'void Treap::clear()':
foo.cc:26:20: error: 'mp' was not declared in this scope
   26 |         T.clear(), mp.clear();
      |                    ^~
foo.cc: In member function 'void Treap::insert(long long int)':
foo.cc:31:17: error: 'mp' was not declared in this scope
   31 |         int c = mp[x]++;
      |                 ^~
foo.cc: In member function 'void Treap::erase(long long int)':
foo.cc:37:17: error: 'mp' was not declared in this scope
   37 |         int c = mp[x];
      |                 ^~
foo.cc: In member function 'int Treap::count(long long int)':
foo.cc:54:17: error: 'mp' was not declared in this scope
   54 |         int c = mp[--x];
      |                 ^~

Code

#include<bits/stdc++.h>
#define ll long long
using namespace std;


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// Template of Multi Ordered set 
struct Treap{ /// hash = 96814
    int len;
    const int ADD = 1000010;
    const int MAXVAL = 1000000010;
    tr1::unordered_map <long long, int> mp; /// Change to int if only int in treap
    tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> T;

    Treap(){
        len = 0;
        T.clear(), mp.clear();
    }

    inline void clear(){
        len = 0;
        T.clear(), mp.clear();
    }

    inline void insert(long long x){
        len++, x += MAXVAL;
        int c = mp[x]++;
        T.insert((x * ADD) + c);
    }

    inline void erase(long long x){
        x += MAXVAL;
        int c = mp[x];
        if (c){
            c--, mp[x]--, len--;
            T.erase((x * ADD) + c);
        }
    }

    /// 1-based index, returns the K'th element in the treap, -1 if none exists
    inline long long kth(int k){
        if (k < 1 || k > len) return -1;
        auto it = T.find_by_order(--k);
        return ((*it) / ADD) - MAXVAL;
    }

    /// Count of value < x in treap
    inline int count(long long x){
        x += MAXVAL;
        int c = mp[--x];
        return (T.order_of_key((x * ADD) + c));
    }

    /// Number of elements in treap
    inline int size(){
        return len;
    }
};



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--){
    int n, q;
    cin >> n;
    Treap tt;
    map<int, int> mp1, mp2;
    vector<ll> a(n), mn1(n), mn2(n), mx1(n), mx2(n), ans(n);
    for (int i = 0; i < n; i++){
      cin >> a[i];
      tt.insert(a[i]);
      mp1[a[i]]++;
      int x = tt.count(a[i]);
      mn1[i] = x;
      mx1[i] = (i + 1) - x - mp1[a[i]];
    }
    tt.clear();
    int cnt = 0;
    for (int i = n - 1; i >= 0; i--){
      tt.insert(a[i]);
      mp2[a[i]]++;
      cnt++;
      int x = tt.count(a[i]);
      mn2[i] = x;
      mx2[i] = cnt - x - mp2[a[i]];
    }
    for (int i = 0; i < n; i++){
      ans[i] = mn1[i] * mx2[i] + mn2[i] * mx1[i];
    }
    cin >> q;
    while (q--){
      int j;
      cin >> j;
      j--;
      cout << ans[j] << "\n";
    }
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1079 Roy and Query (Easy Version)
Contest
Brain Booster #6
Language
C++11 (G++ 13.2.0)
Submit At
2024-10-03 17:59:37
Judged At
2024-11-11 02:45:15
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes