#include <iostream>
using namespace std;
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int N, M;
cin >> N >> M;
int tab[N+1][4];
bool czy[N+1][4];
for(int j=0; j<4; ++j)
for(int i=0; i<=N; ++i)
tab[i][j]=0, czy[i][j] = false;
int Beg, End, V;
for(int i=0; i<M; ++i)
{
cin >> Beg >> End >> V;
++tab[Beg][V]; czy[Beg][V] = true;
--tab[End][V]; czy[End][V] = true;
}
int tmp=0;
for(int j=1; j<4; ++j)
for(int i=1; i<=N; ++i)
{
tmp = 0;
tmp += tab[i][j];
while((tmp || czy[i][j]) && i<=N)
{
tab[i][0] += j;
++i;
if(i<=N)
tmp += tab[i][j];
}
}
int Wynik=0;
for(int i=1; i<=N; ++i)
{
if(tab[i][0] == 3)
Wynik++;
}
/* for(int j=0; j<4; ++j) {
for(int i=1; i<=N; ++i)
cout << tab[i][j] << ' ';
cout << '\n';
}*/
cout << Wynik << '\n';
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 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 | #include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); int N, M; cin >> N >> M; int tab[N+1][4]; bool czy[N+1][4]; for(int j=0; j<4; ++j) for(int i=0; i<=N; ++i) tab[i][j]=0, czy[i][j] = false; int Beg, End, V; for(int i=0; i<M; ++i) { cin >> Beg >> End >> V; ++tab[Beg][V]; czy[Beg][V] = true; --tab[End][V]; czy[End][V] = true; } int tmp=0; for(int j=1; j<4; ++j) for(int i=1; i<=N; ++i) { tmp = 0; tmp += tab[i][j]; while((tmp || czy[i][j]) && i<=N) { tab[i][0] += j; ++i; if(i<=N) tmp += tab[i][j]; } } int Wynik=0; for(int i=1; i<=N; ++i) { if(tab[i][0] == 3) Wynik++; } /* for(int j=0; j<4; ++j) { for(int i=1; i<=N; ++i) cout << tab[i][j] << ' '; cout << '\n'; }*/ cout << Wynik << '\n'; return 0; } |
English