Firms operate at the point where marginal cost equals marginal revenue. Where that point falls below demand, there will be a shortage in the market. This shortage will cause prices (and, therefore, profits) to rise.
In a perfectly competitive market, new firms will enter the market in order to capture a share of excess profits. In the long run, supply will shift outward as more firms enter. As supply increases, prices will fall along with marginal revenue. This will continue until marginal cost, marginal revenue, and demand are equal. Thus, in perfectly competitive markets, resources are allocated such that supply exactly meets demand. In other words, resource allocation is efficient.
In oligopolies, new firms are not able to easily enter the market. Therefore, no long-run shift in supply due to new firms entering will occur. If existing firms continue to operate where supply falls short of demand, prices will remain high, and excess profits will remain in the market. Because resources are not being allocated such that supply meets demand, these markets are inefficient.