Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const int maxn = 300000 + 100;
- int n, m, cnt0, tmp;
- int l[maxn], r[maxn], num[maxn], cnt1[maxn];
- int main() {
- #ifdef ExRoc
- freopen("test.txt", "r", stdin);
- #endif
- ios::sync_with_stdio(false);
- cin >> n >> m;
- for (int i = 0; i < m; ++i) {
- cin >> l[i] >> r[i];
- ++num[l[i]];
- --num[r[i] + 1];
- }
- for (int i = 1; i <= n; ++i) {
- tmp += num[i];
- cnt1[i] = cnt1[i - 1];
- if (tmp == 0) {
- ++cnt0;
- } else if (tmp == 1) {
- ++cnt1[i];
- }
- }
- for (int i = 0; i < m; ++i) {
- cout << cnt0 + cnt1[r[i]] - cnt1[l[i] - 1] << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement