C++ solution using Fenwick Tree + Binary Search
Solution:\n```\ntemplate\nclass BIT {\npublic:\n    vector bit;\n    int n;\n    \n    BIT() {}\n    \n    BIT(int _n) {\n        n = _n;\n        bit = vector(
**Solution:**\n```\ntemplate<typename T>\nclass BIT {\npublic:\n    vector<T> bit;\n    int n;\n    \n    BIT() {}\n    \n    BIT(int _n) {\n        n = _n;\n        bit = vector<T>(n, 0LL);\n    }\n    \n    void inc(int idx, T val) {\n        for(int i = idx + 1; i <= n; i += (i & -i)) \n            bit[i - 1] += val;\n    }\n    \n    T at(int idx) {\n        T res = 0;\n        for(int i = idx + 1; i > 0; i -= (i & -i)) \n            res += bit[i - 1];\n        return res;\n    }\n    \n    T at(int l, int r) {\n        return at(r) - (l - 1 >= 0? at(l - 1): 0);\n    }\n    \n};\n\nclass LUPrefix {\npublic:\n    BIT<int> bit;\n    \n    LUPrefix(int n) {\n        bit = BIT<int>(1e5 + 2);    \n    }\n    \n    void upload(int video) {\n        bit.inc(video, 1);\n    }\n    \n    int longest() {\n        int l = 0, r = 1e5 + 1;\n        while(r - l > 1) {\n            int m = l + (r - l) / 2;\n            if(bit.at(1, m) >= m) l = m;\n            else r = m;\n        }\n        return l;\n    }\n};\n\n/**\n * Your LUPrefix object will be instantiated and called as such:\n * LUPrefix* obj = new LUPrefix(n);\n * obj->upload(video);\n * int param_2 = obj->longest();\n */
['Binary Indexed Tree', 'Binary Tree']