#include <bits/stdc++.h>
using namespace std;
const int T = 1 << 20;
struct kol{
bool a,b,c;
};
struct kol1{
int a,b,c;
};
kol Tree[T * 2];
int res = 0;
vector<int> v;
void upd(int a, int x){
if(x == 1)
Tree[a].a = true;
if(x == 2)
Tree[a].b = true;
if(x == 3)
Tree[a].c = true;
}
kol1 upd1(int x, kol1 a){
if(Tree[x].a == true)
a.a++;
if(Tree[x].b == true)
a.b++;
if(Tree[x].c == true)
a.c++;
return a;
}
kol1 upd2(int x, kol1 a){
if(Tree[x].a == true)
a.a--;
if(Tree[x].b == true)
a.b--;
if(Tree[x].c == true)
a.c--;
return a;
}
void change(int l, int r, int x){
l += T; r += T;
if(l == r)
upd(l,x);
else{
upd(l,x); upd(r,x);
while(l / 2 != r / 2){
if(l % 2 == 0){
upd(l+1,x);
}
if(r % 2 == 1){
upd(r-1,x);
}
l/=2; r/=2;
}
}
}
void query(int x, kol1 a){
a = upd1(x,a);
if(x < T){
query(x * 2, a);
query(x * 2 + 1, a);
}
else{
//cout << x << " " << a.a << " " << a.b << " " << a.c << "\n";
if(a.a > 0 and a.b > 0 and a.c == 0){
v.push_back(1);
}
}
a = upd2(x,a);
}
int main(){
ios_base::sync_with_stdio();
cin.tie();
cout.tie();
int n,m; cin >> n >> m;
for(int i=0; i<m; i++){
int a,b,x; cin >> a >> b >> x;
change(a,b,x);
}
// for(int i=1; i<= T * 2; i++){
// cout << i << " " << Tree[i].a << " " << Tree[i].b << " " << Tree[i].c << "\n";
// }
kol1 a; a.a = 0, a.b = 0, a.c = 0;
query(1, a);
cout << v.size() << "\n";
}
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 77 78 79 80 81 82 83 84 85 86 87 | #include <bits/stdc++.h> using namespace std; const int T = 1 << 20; struct kol{ bool a,b,c; }; struct kol1{ int a,b,c; }; kol Tree[T * 2]; int res = 0; vector<int> v; void upd(int a, int x){ if(x == 1) Tree[a].a = true; if(x == 2) Tree[a].b = true; if(x == 3) Tree[a].c = true; } kol1 upd1(int x, kol1 a){ if(Tree[x].a == true) a.a++; if(Tree[x].b == true) a.b++; if(Tree[x].c == true) a.c++; return a; } kol1 upd2(int x, kol1 a){ if(Tree[x].a == true) a.a--; if(Tree[x].b == true) a.b--; if(Tree[x].c == true) a.c--; return a; } void change(int l, int r, int x){ l += T; r += T; if(l == r) upd(l,x); else{ upd(l,x); upd(r,x); while(l / 2 != r / 2){ if(l % 2 == 0){ upd(l+1,x); } if(r % 2 == 1){ upd(r-1,x); } l/=2; r/=2; } } } void query(int x, kol1 a){ a = upd1(x,a); if(x < T){ query(x * 2, a); query(x * 2 + 1, a); } else{ //cout << x << " " << a.a << " " << a.b << " " << a.c << "\n"; if(a.a > 0 and a.b > 0 and a.c == 0){ v.push_back(1); } } a = upd2(x,a); } int main(){ ios_base::sync_with_stdio(); cin.tie(); cout.tie(); int n,m; cin >> n >> m; for(int i=0; i<m; i++){ int a,b,x; cin >> a >> b >> x; change(a,b,x); } // for(int i=1; i<= T * 2; i++){ // cout << i << " " << Tree[i].a << " " << Tree[i].b << " " << Tree[i].c << "\n"; // } kol1 a; a.a = 0, a.b = 0, a.c = 0; query(1, a); cout << v.size() << "\n"; } |
English