#include<iostream>
using namespace std;
const long long MAX_N=2097160;
const long long S_D=1048576;
bool drzewo[MAX_N][3];
int n,m,wynik=0;
long long wypisz(int x) // zapytanie
{
bool ret=false,ret2=false,ret3=false;
//x+=comp;
while(x)
{
if(drzewo[x][0]==true&&ret==false) ret=true;
if(drzewo[x][1]==true&&ret2==false) ret2=true;
if(drzewo[x][2]==true&&ret3==false) ret3=true;
x>>=1;
}
if(ret&&ret2&&!ret3) return true;
else return false;
}
void zakt(int a, int b, int c) // insert
{
//a+=comp;
//b+=comp;
while(a<b)
{
if(a&1)
{
drzewo[a][c]=true;
a>>=1;
++a;
}
else
{
a>>=1;
}
if(b&1)
{
b>>=1;
}
else
{
drzewo[b][c]=true;
b>>=1;
--b;
}
}
if(a==b)
{
drzewo[a][c]=true;
}
}
int main()
{
cin>>n>>m;
for(int i=S_D; i<S_D+m; i++)
{
int temp, temp2, temp3;
cin>>temp>>temp2>>temp3;
temp3--;
zakt(S_D+temp,S_D+temp2,temp3);
}
for(int i=1; i<=n; i++)
{
if(wypisz(S_D+i)) wynik++;
}
cout<<wynik;
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<iostream> using namespace std; const long long MAX_N=2097160; const long long S_D=1048576; bool drzewo[MAX_N][3]; int n,m,wynik=0; long long wypisz(int x) // zapytanie { bool ret=false,ret2=false,ret3=false; //x+=comp; while(x) { if(drzewo[x][0]==true&&ret==false) ret=true; if(drzewo[x][1]==true&&ret2==false) ret2=true; if(drzewo[x][2]==true&&ret3==false) ret3=true; x>>=1; } if(ret&&ret2&&!ret3) return true; else return false; } void zakt(int a, int b, int c) // insert { //a+=comp; //b+=comp; while(a<b) { if(a&1) { drzewo[a][c]=true; a>>=1; ++a; } else { a>>=1; } if(b&1) { b>>=1; } else { drzewo[b][c]=true; b>>=1; --b; } } if(a==b) { drzewo[a][c]=true; } } int main() { cin>>n>>m; for(int i=S_D; i<S_D+m; i++) { int temp, temp2, temp3; cin>>temp>>temp2>>temp3; temp3--; zakt(S_D+temp,S_D+temp2,temp3); } for(int i=1; i<=n; i++) { if(wypisz(S_D+i)) wynik++; } cout<<wynik; return 0; } |
English