/*               ∧∧∩               ( ゚∀゚)/ キタ━━━━━━(゚∀゚)━━━━━━!!!!             ⊂   ノ  ゆっくり見てってね!!!!!!!!              (つ ノ     o          (ノ      \      ☆              |      o           (⌒ ⌒ヽ   /     ☆     \  (´⌒  ⌒  ⌒ヾ   /       ('⌒ ; ⌒   ::⌒  )      (´     )     ::: ) /   ☆─ (´⌒;:    ::⌒`) :;  ) */ #include #include using namespace std; using namespace atcoder; #define rep(i, s, n) for(int i=s; i std::istream &operator>>(std::istream&is,std::vector&v){for(T &in:v){is>>in;}return is;} template std::ostream &operator<<(std::ostream&os,const std::vector&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;} // 回文かどうかの判定 bool iskaibun(string s){ll k = s.size();rep(i,0,k/2){if(s[i]!=s[k-1-i]){return false;}}return true;} template void chmax(T& a, T b) { if (a < b) a = b; } template void chmin(T& a, T b) { if (a > b) a = b; } // 余りが正になるような割り方 ll floor(ll x, ll m) { ll r = (x % m + m) % m; return (x - r) / m; } #define mod 998244353 using mint = modint998244353; int op(int a, int b) {return max(a, b);} int e() {return 0;} int mapping(int f, int x) {return (f == 1e9 ? x : f);} int composition(int f, int g) {return (f == 1e9 ? g : f);} int id() {return 1e9;} signed main() { cin.tie(nullptr); cout << fixed << setprecision(10); ios::sync_with_stdio(false); int n, q; cin >> n >> q; vector a(n); cin >>a; vector b; rep(i, 0, n) { if(b.size() && *lower_bound(all(b), a[i]) == a[i]) continue; else b.push_back(a[i]); } vector c(n); rep(i, 0, n) c[i] = lower_bound(all(b), a[i]) - b.begin(); cout << c << endl; while(q--) { int x, y; cin >> x >> y; x--; y--; cout << max(0, c[x]-c[y]-1) << endl; } }