3159.cpp (430B)
1 class Solution { 2 public: 3 vector<int> occurrencesOfElement(vector<int> &nums, vector<int> &queries, int x) { 4 static int count[100001]; 5 int sz = 1; 6 7 for (int i = 0; i < size(nums); i++) { 8 if (nums[i] != x) continue; 9 count[sz++] = i; 10 } 11 12 for (auto &query : queries) { 13 query = query < sz ? count[query] : -1; 14 } 15 16 return queries; 17 } 18 };