#include<bits/stdc++.h>
using namespace std;
int n,m,r,y,b,re[2][1000010],ye[2][1000010],bl[2][1000010],a,x,c,wyn;
bool u,o,p;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>m>>n;
for(int i=0;i<n;i++)
{
cin>>a>>x>>c;
if(c==1)
{
ye[0][y]=a;
ye[1][y]=x;
y++;
continue;
}
if(c==2)
{
bl[0][b]=a;
bl[1][b]=x;
b++;
continue;
}if(c==3)
{
re[0][r]=a;
re[1][r]=x;
r++;
continue;
}
}
for(int i=1;i<m;i++)
{
u=0;
o=0;
p=0;
for(int j=0;j<y;j++)
{
if(ye[0][j]<=i&&i<=ye[1][j])
{
u=1;
break;
}
}
for(int j=0;j<b;j++)
{
if(bl[0][j]<=i&&i<=bl[1][j])
{
o=1;
break;
}
}
for(int j=0;j<r;j++)
{
if(re[0][j]<=i&&i<=re[1][j])
{
p=1;
break;
}
}
if(u==1&&o==1&&p==0)
{
wyn++;
}
}
cout<<wyn;
}
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 64 65 66 67 68 69 70 | #include<bits/stdc++.h> using namespace std; int n,m,r,y,b,re[2][1000010],ye[2][1000010],bl[2][1000010],a,x,c,wyn; bool u,o,p; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>m>>n; for(int i=0;i<n;i++) { cin>>a>>x>>c; if(c==1) { ye[0][y]=a; ye[1][y]=x; y++; continue; } if(c==2) { bl[0][b]=a; bl[1][b]=x; b++; continue; }if(c==3) { re[0][r]=a; re[1][r]=x; r++; continue; } } for(int i=1;i<m;i++) { u=0; o=0; p=0; for(int j=0;j<y;j++) { if(ye[0][j]<=i&&i<=ye[1][j]) { u=1; break; } } for(int j=0;j<b;j++) { if(bl[0][j]<=i&&i<=bl[1][j]) { o=1; break; } } for(int j=0;j<r;j++) { if(re[0][j]<=i&&i<=re[1][j]) { p=1; break; } } if(u==1&&o==1&&p==0) { wyn++; } } cout<<wyn; } |
English