//Mieszanie Kolorow
//Mateusz Wasilewski
#include <bits/stdc++.h>
using namespace std;
int N,M;
int a,b,c,wynik;
const int half=1048576;
int tree[half*2];
void add(int x, int y, int k);
int ask(int x);
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> M;
for(int i=0; i^M; ++i){
cin >> a >> b >> c;
add(a-1, b-1, 1<<(c-1));
}
for(int i=0; i^N; ++i){
wynik += (ask(i) == 3);
}
cout << wynik << "\n";
return 0;
}
int ask(int x){
x += half;
int k = 0;
while(true){
k |= tree[x];
if(x==1) break;
x/=2;
}
return k;
}
void add(int x, int y, int k){
x += half;
y += half;
while(x<=y){
if(x%2){
tree[x] |= k;
x++;
}
if(!(y%2)){
tree[y] |= k;
y--;
}
x/=2;
y/=2;
}
return;
}
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 | //Mieszanie Kolorow //Mateusz Wasilewski #include <bits/stdc++.h> using namespace std; int N,M; int a,b,c,wynik; const int half=1048576; int tree[half*2]; void add(int x, int y, int k); int ask(int x); int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> M; for(int i=0; i^M; ++i){ cin >> a >> b >> c; add(a-1, b-1, 1<<(c-1)); } for(int i=0; i^N; ++i){ wynik += (ask(i) == 3); } cout << wynik << "\n"; return 0; } int ask(int x){ x += half; int k = 0; while(true){ k |= tree[x]; if(x==1) break; x/=2; } return k; } void add(int x, int y, int k){ x += half; y += half; while(x<=y){ if(x%2){ tree[x] |= k; x++; } if(!(y%2)){ tree[y] |= k; y--; } x/=2; y/=2; } return; } |
English