Using Segment Tree Approach
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass LUPrefix {\npublic:\n    int tot=0;\n    vector<bool> tree;\n\n    void update(int video,int node,int st,int en)\n    {\n        if(st==en)\n        {\n            if(st==video)\n                tree[node]=true;\n            return;\n        }\n        int mid=(st+en)/2;\n        if(video<=mid)\n            update(video,2*node,st,mid);\n        else\n            update(video,2*node+1,mid+1,en);\n        \n        tree[node]=tree[2*node]&tree[2*node+1];\n    }\n\n    int query(int node,int st,int en)\n    {\n        if(st==en)\n            return tree[node]?en:0;\n        if(tree[node])\n            return en;\n        int mid=(st+en)/2;\n        return (tree[2*node]==0)? query(2*node,st,mid) : max(mid,query(2*node+1,mid+1,en));\n    }\n\n    LUPrefix(int n) {\n        tot=n;\n        tree.resize(4*n);\n    }\n\n    void upload(int video) {\n        update(video,1,1,tot);        \n    }\n    \n    int longest() {\n        return query(1,1,tot);\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 */\n```
['Segment Tree', 'C++']