In LONGMAN dictionary, the pronunciation of the word elementary is /ˌeləˈmentəri/. However, I heard some people pronounced it like /ˌeləˈmentri/. How should I pronounce the word correctly?
Both of them are correct.
The first one has 5 syllables while the second one has 4. It depends on the dialect of English. Some British and American dialects have lost the weak syllable (second last in 'elementary'—/tə/) so they pronounce it with 4 syllables, but both are equally correct and acceptable.
In English, when a stressed syllable is followed by two (or more) unstressed syllables, the vowel immediately following the stressed syllable is usually dropped in colloquial/fast speech (not every accent/dialect and not in every individual's speech). The pronunciation varies from individual to individual. The process is called syncope. Other examples include: comfortable, camera, family, average etc.
In most dialects, the emboldened vowels have been syncopated, however, some dialects have retained them and still pronounce them.