Hash trick---two case not passing
#include #include #include #include using namespace std ; #define ll long long map<ll,ll> m ; bool mycompare(ll a,ll b){ return m[a] < m[b] ; } void trick(ll *a,ll n){ vector v ; //int val=0 ; for(ll i = 0 ; i < n ;i++){ if(m.count(a[i]) ==0){ v.push_back(a[i]) ; m[a[i]] = i ; } else{ m[a[i]] = i ; } } sort(v.begin(),v.end(),mycompare) ; for(ll i = 0 ; i<v.size();i++){ cout << v[i] << endl ; } } int main() { ll n ; cin >> n ; ll a[n] ; for(ll i = 0 ;i < n ;i++){ cin >> a[i] ; } trick(a,n) ; return 0; }
one test case is not passing still!