#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef LOCAL
#define debug(...) __VA_ARGS__
#else
#define debug(...) {}
#endif
struct color{
int r,y,b;
};
const int base = (1<<20);
bool tree[2*base][4];
void change(int a, int b, int x){
a += base-1;
b += base+1;
while (b-a > 1){
if (!(a%2)) tree[a+1][x] = 1;
if (b%2) tree[b-1][x] = 1;
a /= 2;
b /= 2;
}
}
color query(int v){
v += base;
color x;
x.r = 0;
x.y = 0;
x.b = 0;
while (v){
x.y |= tree[v][1];
x.b |= tree[v][2];
x.r |= tree[v][3];
v /= 2;
}
return x;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
int i;
int n,m;
cin>>n>>m;
while (m--){
int a,b,x;
cin>>a>>b>>x;
change(a,b,x);
}
int wy = 0;
for (i = 1; i < n+1; i++){
color akt = query(i);
if (akt.y && akt.b && (!akt.r)) wy++;
}
cout<<wy<<"\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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; #ifdef LOCAL #define debug(...) __VA_ARGS__ #else #define debug(...) {} #endif struct color{ int r,y,b; }; const int base = (1<<20); bool tree[2*base][4]; void change(int a, int b, int x){ a += base-1; b += base+1; while (b-a > 1){ if (!(a%2)) tree[a+1][x] = 1; if (b%2) tree[b-1][x] = 1; a /= 2; b /= 2; } } color query(int v){ v += base; color x; x.r = 0; x.y = 0; x.b = 0; while (v){ x.y |= tree[v][1]; x.b |= tree[v][2]; x.r |= tree[v][3]; v /= 2; } return x; } int main(){ ios_base::sync_with_stdio(0); cin.tie(); cout.tie(); int i; int n,m; cin>>n>>m; while (m--){ int a,b,x; cin>>a>>b>>x; change(a,b,x); } int wy = 0; for (i = 1; i < n+1; i++){ color akt = query(i); if (akt.y && akt.b && (!akt.r)) wy++; } cout<<wy<<"\n"; return 0; } |
English