#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int n;
void modify(vector<int> &t,int l,int p,int value)
{
l+=n-1;
p+=n;
while(l<p)
{
// cout<<"L "<<l<<" P "<<p<<endl;
if (l&1) t[l++] += value;
if (p&1) t[--p] += value;
l=l>>1;
p=p>>1;
}
}
void push(vector<int> &t)
{
for (int i = 1; i < n; ++i)
{
t[i<<1] += t[i];
t[i<<1|1] += t[i];
t[i] = 0;
}
}
int main()
{
ios_base::sync_with_stdio(0);
int m;
cin>>n>>m;
int LOG=1;
while( (1<<LOG)<n) LOG++;
n=pow(2,LOG);
vector<int> N(2*n+1,0);
vector<int> Z(2*n+1,0);
vector<int> C(2*n+1,0);
int l=n;
while(m--)
{
int a,b,c;
cin>>a>>b>>c;
if(c==2) modify(N,a,b,1);
else if(c==3) modify(C,a,b,1);
else if(c==1) modify(Z,a,b,1);
}
int result=0;
push(N);
push(Z);
push(C);
for(int i=0 ; i<l ; i++)
{
//cout<<"Ni "<<N[i+n]<<endl;
//cout<<"Zi "<<Z[i+n]<<endl;
if(N[i+n]>=1 && Z[i+n]>=1 && C[i+n]==0)result++;
}
cout<<result<<endl;
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 58 59 60 61 62 | #include<iostream> #include<vector> #include<cmath> using namespace std; int n; void modify(vector<int> &t,int l,int p,int value) { l+=n-1; p+=n; while(l<p) { // cout<<"L "<<l<<" P "<<p<<endl; if (l&1) t[l++] += value; if (p&1) t[--p] += value; l=l>>1; p=p>>1; } } void push(vector<int> &t) { for (int i = 1; i < n; ++i) { t[i<<1] += t[i]; t[i<<1|1] += t[i]; t[i] = 0; } } int main() { ios_base::sync_with_stdio(0); int m; cin>>n>>m; int LOG=1; while( (1<<LOG)<n) LOG++; n=pow(2,LOG); vector<int> N(2*n+1,0); vector<int> Z(2*n+1,0); vector<int> C(2*n+1,0); int l=n; while(m--) { int a,b,c; cin>>a>>b>>c; if(c==2) modify(N,a,b,1); else if(c==3) modify(C,a,b,1); else if(c==1) modify(Z,a,b,1); } int result=0; push(N); push(Z); push(C); for(int i=0 ; i<l ; i++) { //cout<<"Ni "<<N[i+n]<<endl; //cout<<"Zi "<<Z[i+n]<<endl; if(N[i+n]>=1 && Z[i+n]>=1 && C[i+n]==0)result++; } cout<<result<<endl; return 0; } |
English