#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
vector<long long> szamok;
for (long long i = 0; n > i; i++) {
long long temp;
cin >> temp;
szamok.push_back(temp);
}
vector<pair<long long, long long>> long longer;
for (long long i = 0; m > i; i++) {
long long a, b;
cin >> a >> b;
a--;
b--;
long longer.push_back({a, b});
}
sort(long longer.begin(), long longer.end());
vector<pair<long long, long long>> reallong longer;
long long currentStart = -1;
long long currentEnd = -1;
for (long long i = 0; m > i; i++) {
pair<long long, long long> current = long longer[i];
if (currentStart == -1) {
currentStart = current.first;
currentEnd = current.second;
} else if (currentEnd >= current.first) {
// Ez egybeesik
currentEnd = current.second;
} else {
reallong longer.push_back({currentStart, currentEnd});
currentStart = current.first;
currentEnd = current.second;
}
}
if (currentStart != -1) {
reallong longer.push_back({currentStart, currentEnd});
}
long long megoldas = 0;
for (auto curr : reallong longer) {
long long start = curr.first;
long long end = curr.second;
vector<long long> sublong longer;
for (long long i = start; end >= i; i++) {
sublong longer.push_back(szamok[i]);
}
sort(sublong longer.begin(), sublong longer.end());
for (long long i = 0; sublong longer.size() > i; i++) {
if (sublong longer[i] == start+i+1) {
megoldas++;
}
}
}
long long lastIndex = 0;
for (auto curr : reallong longer) {
for (long long i = lastIndex; n > i && curr.first > i; i++) {
if (i+1 == szamok[i]) {
megoldas++;
}
}
lastIndex = curr.second+1;
}
cout << megoldas << endl;
return 0;
}
exit status 1
main.cpp: In function 'int main()':
main.cpp:17:40: error: 'long' specified with 'std::vector<std::pair<long long int, long long int> >'
17 | vector<pair<long long, long long>> long longer;
| ^~~~
main.cpp:26:20: error: expected initializer before '.' token
26 | long longer.push_back({a, b});
| ^
main.cpp:26:37: error: expected primary-expression before ')' token
26 | long longer.push_back({a, b});
| ^
main.cpp:29:10: error: expected primary-expression before 'long'
29 | sort(long longer.begin(), long longer.end());
| ^~~~
main.cpp:29:31: error: expected primary-expression before 'long'
29 | sort(long longer.begin(), long longer.end());
| ^~~~
main.cpp:31:49: error: expected initializer before 'longer'
31 | vector<pair<long long, long long>> reallong longer;
| ...