#include <bits/stdc++.h>
using namespace std;
int n, m, l, r, nr;
bool tab[2100000][5];
bool wynik[5];
int pot2[23];
int wyjscie;
void zaktualizuj(int p, int k, int f);
int sprawdz(int x);
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
pot2[0]=1;
for(int i=1; i<=22; i++)
{
pot2[i]=pot2[i-1]*2;
}
for(int i=0; i<m; i++)
{
cin >> l >> r >> nr;
zaktualizuj((l-1), (r-1), nr);
}
for(int i=0; i<n; i++)
{
wyjscie+=sprawdz(i);
}
cout << wyjscie << '\n';
return 0;
}
void zaktualizuj(int p, int k, int f)
{
p+=pot2[20];
k+=pot2[20];
tab[p][f]=1;
if(p!=k)
{
tab[k][f]=1;
while((p+1)!=k)
{
if(p%2==0)
{
tab[p+1][f]=1;
}
if(k%2==1)
{
tab[k-1][f]=1;
}
p/=2;
k/=2;
}
}
}
int sprawdz(int x)
{
x+=pot2[20];
wynik[1]=0;
wynik[2]=0;
wynik[3]=0;
while(x!=0)
{
if(tab[x][1]==1)
wynik[1]=1;
if(tab[x][2]==1)
wynik[2]=1;
if(tab[x][3]==1)
wynik[3]=1;
x/=2;
}
if(wynik[1]==1 && wynik[2]==1 && wynik[3]==0)
return 1;
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | #include <bits/stdc++.h> using namespace std; int n, m, l, r, nr; bool tab[2100000][5]; bool wynik[5]; int pot2[23]; int wyjscie; void zaktualizuj(int p, int k, int f); int sprawdz(int x); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; pot2[0]=1; for(int i=1; i<=22; i++) { pot2[i]=pot2[i-1]*2; } for(int i=0; i<m; i++) { cin >> l >> r >> nr; zaktualizuj((l-1), (r-1), nr); } for(int i=0; i<n; i++) { wyjscie+=sprawdz(i); } cout << wyjscie << '\n'; return 0; } void zaktualizuj(int p, int k, int f) { p+=pot2[20]; k+=pot2[20]; tab[p][f]=1; if(p!=k) { tab[k][f]=1; while((p+1)!=k) { if(p%2==0) { tab[p+1][f]=1; } if(k%2==1) { tab[k-1][f]=1; } p/=2; k/=2; } } } int sprawdz(int x) { x+=pot2[20]; wynik[1]=0; wynik[2]=0; wynik[3]=0; while(x!=0) { if(tab[x][1]==1) wynik[1]=1; if(tab[x][2]==1) wynik[2]=1; if(tab[x][3]==1) wynik[3]=1; x/=2; } if(wynik[1]==1 && wynik[2]==1 && wynik[3]==0) return 1; return 0; } |
English