#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int t[3][N];
int main()
{
ios_base::sync_with_stdio(0);
int n, m;
cin>>n>>m;
while(m--){
int l, r, col;
cin>>l>>r>>col;
col--;
t[col][l]++;
t[col][r+1]--;
}
int ans=0;
for(int i=1; i<=n; ++i){
t[0][i]+=t[0][i-1];
t[1][i]+=t[1][i-1];
t[2][i]+=t[2][i-1];
if(t[0][i]>0 && t[1][i]>0 && t[2][i]==0) ans++;
}
cout<<ans;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <bits/stdc++.h> using namespace std; const int N=1e6+10; int t[3][N]; int main() { ios_base::sync_with_stdio(0); int n, m; cin>>n>>m; while(m--){ int l, r, col; cin>>l>>r>>col; col--; t[col][l]++; t[col][r+1]--; } int ans=0; for(int i=1; i<=n; ++i){ t[0][i]+=t[0][i-1]; t[1][i]+=t[1][i-1]; t[2][i]+=t[2][i-1]; if(t[0][i]>0 && t[1][i]>0 && t[2][i]==0) ans++; } cout<<ans; return 0; } |
English