#include<bits/stdc++.h>
#define VAR(i,n) __typeof(n) i = (n)
#define loop(i,j,s) for(int i=j;i<s;i++)
#define loopback(i,j,s) for(int i=j;i>=s;i--)
#define foreach(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define pln( x ) cout << x << "\n"
#define ps( x ) cout << x << " "
#define entr cout << "\n"
#define pcnt(i) __builtin_popcount(i)
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define SIZE(c) (c).size()
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<vector<int> > VVI;
const int INFTY=20000000;
const int MAX=1000100;
const int MOD=10000000;
void coutTab(int* tab,int n){
loop(i,0,n){
cout<<tab[i]<<" ";
}
cout<<"\n";
}
template<class T> void coutVec(vector<T> tab){
for(T t : tab){
cout<<t<<" ";
}
cout<<"\n";
}
//------------------------------------------
struct Node {
int z,n,c;
Node() : z(0), n(0), c(0) {};
Node(int _z, int _n, int _c) : z(_z), n(_n), c(_c) {};
Node operator+(Node & b) const {
Node r;
r.z = z + b.z;
r.n = n + b.n;
r.c = c + b.c;
return r;
}
};
int n;
int D;
Node tree[4*MAX];
void init() {
D=1;
while(D<n) {
D*=2;
}
loop(i,0,2*D) {
tree[i] = Node(0,0,0);
}
}
void add(int L, int R, Node n) {
L += D;
R += D;
while(L < R) {
if(L%2==1) {
tree[L] = tree[L] + n;
}
if(R%2==0) {
tree[R] = tree[R] + n;
}
L=(L+1)/2;
R=(R-1)/2;
}
if(L==R) {
tree[L] = tree[L] + n;
}
}
Node read(int i) {
i += D;
Node res(0,0,0);
while(i>0) {
res = res + tree[i];
i/=2;
}
return res;
}
int main(){
ios_base::sync_with_stdio(0);
int q;
cin>>n>>q;
init();
int l, r, k;
while(q--) {
cin>>l>>r>>k;
Node n;
if(k==1) n.z = 1;
else if(k==2) n.n = 1;
else if(k==3) n.c = 1;
add(l-1,r-1, n);
}
int res=0;
loop(i,0,n) {
Node n = read(i);
if(n.n>0 && n.z >0 && n.c == 0) res++;
}
pln(res);
}
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | #include<bits/stdc++.h> #define VAR(i,n) __typeof(n) i = (n) #define loop(i,j,s) for(int i=j;i<s;i++) #define loopback(i,j,s) for(int i=j;i>=s;i--) #define foreach(i,c) for(VAR(i,(c).begin());i!=(c).end();i++) #define pln( x ) cout << x << "\n" #define ps( x ) cout << x << " " #define entr cout << "\n" #define pcnt(i) __builtin_popcount(i) #define ll long long #define pb push_back #define mp make_pair #define ff first #define ss second #define SIZE(c) (c).size() #define ALL(c) (c).begin(), (c).end() using namespace std; typedef vector<int> VI; typedef pair<int, int> PII; typedef vector<vector<int> > VVI; const int INFTY=20000000; const int MAX=1000100; const int MOD=10000000; void coutTab(int* tab,int n){ loop(i,0,n){ cout<<tab[i]<<" "; } cout<<"\n"; } template<class T> void coutVec(vector<T> tab){ for(T t : tab){ cout<<t<<" "; } cout<<"\n"; } //------------------------------------------ struct Node { int z,n,c; Node() : z(0), n(0), c(0) {}; Node(int _z, int _n, int _c) : z(_z), n(_n), c(_c) {}; Node operator+(Node & b) const { Node r; r.z = z + b.z; r.n = n + b.n; r.c = c + b.c; return r; } }; int n; int D; Node tree[4*MAX]; void init() { D=1; while(D<n) { D*=2; } loop(i,0,2*D) { tree[i] = Node(0,0,0); } } void add(int L, int R, Node n) { L += D; R += D; while(L < R) { if(L%2==1) { tree[L] = tree[L] + n; } if(R%2==0) { tree[R] = tree[R] + n; } L=(L+1)/2; R=(R-1)/2; } if(L==R) { tree[L] = tree[L] + n; } } Node read(int i) { i += D; Node res(0,0,0); while(i>0) { res = res + tree[i]; i/=2; } return res; } int main(){ ios_base::sync_with_stdio(0); int q; cin>>n>>q; init(); int l, r, k; while(q--) { cin>>l>>r>>k; Node n; if(k==1) n.z = 1; else if(k==2) n.n = 1; else if(k==3) n.c = 1; add(l-1,r-1, n); } int res=0; loop(i,0,n) { Node n = read(i); if(n.n>0 && n.z >0 && n.c == 0) res++; } pln(res); } |
English