#include<bits/stdc++.h>
using namespace std;
int licz[1000005][3];
int tab[3];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int a,t;
cin>>a>>t;
while(t--)
{
int b,c,d;
cin>>b>>c>>d;
d--;
licz[b][d]++;
licz[c+1][d]--;
}
int res = 0;
for(int x=1;x<=a;x++)
{
for(int y=0;y<3;y++)
tab[y]+=licz[x][y];
if(tab[0] && tab[1] && !tab[2])
res++;
}
cout<<res;
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 27 28 29 | #include<bits/stdc++.h> using namespace std; int licz[1000005][3]; int tab[3]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a,t; cin>>a>>t; while(t--) { int b,c,d; cin>>b>>c>>d; d--; licz[b][d]++; licz[c+1][d]--; } int res = 0; for(int x=1;x<=a;x++) { for(int y=0;y<3;y++) tab[y]+=licz[x][y]; if(tab[0] && tab[1] && !tab[2]) res++; } cout<<res; return 0; } |
English