#include<bits/stdc++.h>
using namespace std;
const int MAKS = (1<<20);
struct Colors
{
int B = 0, R = 0, Y = 0;
};
Colors Tree[2*MAKS];
Colors tab[MAKS];
void add(int l, int r, int x, int u = 1, int lo = 0, int hi = MAKS - 1)
{
if(lo >= l && hi <= r)
{
if(x == 1)
{
Tree[u].Y ++;
} else if(x == 2)
{
Tree[u].B ++;
} else
{
Tree[u].R ++;
}
} else if (lo > r || hi < l)
{
return;
} else
{
add(l,r,x,2*u,lo,(lo+hi)/2);
add(l,r,x,2*u+1,(lo+hi)/2+1,hi);
}
}
void update(int x)
{
int i = x;
x += MAKS;
while(x != 0)
{
tab[i].Y += Tree[x].Y;
tab[i].B += Tree[x].B;
tab[i].R += Tree[x].R;
x /= 2;
}
return;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,m; cin >> n >> m;
while(m--)
{
int a,b,x; cin >> a >> b >> x;
add(a,b,x);
}
int ans = 0;
for(int i = 1; i <= n; i++)
{
update(i);
//cout << tab[i].B << " " << tab[i].R << " " << tab[i].Y << "\n";
if(tab[i].B > 0 && tab[i].Y > 0 && tab[i].R == 0)
{
ans ++;
}
}
cout << ans;
}
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 71 | #include<bits/stdc++.h> using namespace std; const int MAKS = (1<<20); struct Colors { int B = 0, R = 0, Y = 0; }; Colors Tree[2*MAKS]; Colors tab[MAKS]; void add(int l, int r, int x, int u = 1, int lo = 0, int hi = MAKS - 1) { if(lo >= l && hi <= r) { if(x == 1) { Tree[u].Y ++; } else if(x == 2) { Tree[u].B ++; } else { Tree[u].R ++; } } else if (lo > r || hi < l) { return; } else { add(l,r,x,2*u,lo,(lo+hi)/2); add(l,r,x,2*u+1,(lo+hi)/2+1,hi); } } void update(int x) { int i = x; x += MAKS; while(x != 0) { tab[i].Y += Tree[x].Y; tab[i].B += Tree[x].B; tab[i].R += Tree[x].R; x /= 2; } return; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin >> n >> m; while(m--) { int a,b,x; cin >> a >> b >> x; add(a,b,x); } int ans = 0; for(int i = 1; i <= n; i++) { update(i); //cout << tab[i].B << " " << tab[i].R << " " << tab[i].Y << "\n"; if(tab[i].B > 0 && tab[i].Y > 0 && tab[i].R == 0) { ans ++; } } cout << ans; } |
English