403notfound @ 2023-11-13 12:52:13
#include <bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
const ll N = 1e7 + 5;
ll n , m , mp[(ll)1e3 + 5] , ans;
ll d[N * 4] , b[N * 4];
//map <ll , ll> b;
//map <ll , ll> d;
void add(ll l , ll r , ll c , ll s , ll t , ll x){
if (l <= s && t <= r){
d[x] = c * (t - s + 1);
b[x] = c;
return ;
}ll mid = s + (t - s) / 2;
if (b[x]){
b[x * 2] = b[x * 2 + 1] = b[x];
d[x * 2] = (mid - s + 1) * b[x];
d[x * 2 + 1] = (t - mid) * b[x];
b[x] = 0;
}
if (l <= mid) add(l , r , c , s , mid , x * 2);
if (mid < r) add(l , r , c , mid + 1 , t , x * 2 + 1);
d[x] = d[x * 2] + d[x * 2 + 1];
}
ll sum(ll l , ll r , ll s , ll t , ll x){
if (l <= s && t <= r) return d[x];
ll tot = 0 , mid = s + (t - s) / 2;
if (b[x]){
b[x * 2] = b[x * 2 + 1] = b[x];
d[x * 2] = (mid - s + 1) * b[x];
d[x * 2 + 1] = (t - mid) * b[x];
b[x] = 0;
}
if (l <= mid) tot += sum(l , r , s , mid , x * 2);
if (mid < r) tot += sum(l , r , mid + 1 , t , x * 2 + 1);
return tot;
}
signed main(){
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1 , l , r;i <= m;i++){
cin >> l >> r;
add(l , r , i , 1 , n , 1);
}
for (int i = 1;i <= n;i++){
ll pos = sum(i , i , 1 , n , 1);
if (!pos) continue;
// cout << pos << " ";
ans += !mp[pos];
mp[pos] ++;
}
cout << ans << "\n";
return 0;
}
by Kazeno_Akina @ 2023-11-13 13:05:10
建议使用:动态开点
数组大小4e7还开好几个你不MLE就怪了。