#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
constexpr int M=1e6+7;
constexpr int base=1<<20;
int Tree[base<<1];
void add(int a, int b, int x){
a+=base-1;
b+=base+1;
while(b-a>1){
if(!(a&1)) Tree[a+1]|=x;
if(b&1) Tree[b-1]|=x;
a>>=1; b>>=1;
}
}
int query(int v){
int w=0;
v+=base;
while(v){
w|=Tree[v];
v>>=1;
}
return w;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, p, k, a, res=0;
cin >> n >> m;
while(m--){
cin >> p >> k >> a;
add(p,k,1<<(a-1));
}
for(int i=1; i<=n; i++) if(query(i)==3) res++;
cout << res;
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 | #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; constexpr int M=1e6+7; constexpr int base=1<<20; int Tree[base<<1]; void add(int a, int b, int x){ a+=base-1; b+=base+1; while(b-a>1){ if(!(a&1)) Tree[a+1]|=x; if(b&1) Tree[b-1]|=x; a>>=1; b>>=1; } } int query(int v){ int w=0; v+=base; while(v){ w|=Tree[v]; v>>=1; } return w; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, p, k, a, res=0; cin >> n >> m; while(m--){ cin >> p >> k >> a; add(p,k,1<<(a-1)); } for(int i=1; i<=n; i++) if(query(i)==3) res++; cout << res; return 0; } |
English