C++ | Trie
\nclass Solution {\npublic:\n    struct Trie\n    {\n        unordered_map<int,Trie*>child;\n        bool isend;\n        Trie()\n        {\n            isend=f
```\nclass Solution {\npublic:\n    struct Trie\n    {\n        unordered_map<int,Trie*>child;\n        bool isend;\n        Trie()\n        {\n            isend=false;\n        }\n    };\n    Trie *root;\n    int insert(vector<int>&nums,int i,int j)\n    {\n        Trie *p=root;\n        int count=0;\n        for(int k=i;k<=j;k++)\n        {\n            if(p->child[nums[k]]==NULL)\n                p->child[nums[k]]=new Trie();\n            p=p->child[nums[k]];\n            if(!p->isend)\n                count++;\n            p->isend=true;\n        }\n        return count;\n    }\n    int countDistinct(vector<int>& nums, int k, int p) \n    {\n        root=new Trie();\n        int n=nums.size(),res=0;\n        for(int i=0;i<n;i++)\n        {\n            int c=0,j=i;\n            for(j=i;j<n;j++)\n            {\n                if(nums[j]%p==0)\n                    c++;\n                if(c>k)\n                    break;\n            }\n            res+=insert(nums,i,j-1);\n        }\n        return res;\n    }\n};\n```
[]