#include <bits/stdc++.h>
using namespace std;
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
int n;
int m;
cin >> n;
bool c[n+1];
bool ni[n+1];
bool z[n+1];
cin >> m;
int r[m];
int l[m];
int k[m];
for(int i = 0;i<m;i++)
{
cin >> r[i];
cin >> l[i];
cin >> k[i];
}
for(int i2 = 1;i2<n+1;i2++)
{
z[i2] = false;
ni[i2]= false;
c[i2]= true;
}
for(int j = 0;j<m;j++)
{
if(k[j] == 1)
for(int j2 = r[j];j2<l[j]+1;j2++)
{
z[j2] = true;
}
if(k[j] == 2)
for(int j2 = r[j];j2<l[j]+1;j2++)
{
ni[j2] = true;
}
if(k[j] == 3)
for(int j2 = r[j];j2<l[j]+1;j2++)
{
c[j2] = false;
}
}
int d;
d = 0;
for(int i3 = 1; i3<n+1;i3++)
{
if(c[i3]&&z[i3]&&ni[i3])
{
d++;
}
}
cout << d;
}
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | #include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); int n; int m; cin >> n; bool c[n+1]; bool ni[n+1]; bool z[n+1]; cin >> m; int r[m]; int l[m]; int k[m]; for(int i = 0;i<m;i++) { cin >> r[i]; cin >> l[i]; cin >> k[i]; } for(int i2 = 1;i2<n+1;i2++) { z[i2] = false; ni[i2]= false; c[i2]= true; } for(int j = 0;j<m;j++) { if(k[j] == 1) for(int j2 = r[j];j2<l[j]+1;j2++) { z[j2] = true; } if(k[j] == 2) for(int j2 = r[j];j2<l[j]+1;j2++) { ni[j2] = true; } if(k[j] == 3) for(int j2 = r[j];j2<l[j]+1;j2++) { c[j2] = false; } } int d; d = 0; for(int i3 = 1; i3<n+1;i3++) { if(c[i3]&&z[i3]&&ni[i3]) { d++; } } cout << d; } |
English