#include <bits/stdc++.h>
using namespace std;
void Update(int p,int k,int n,vector<bool>&T)
{
p+=n-1;
k+=n;
T[p]=true;
while(p/2!=k/2)
{
if(p%2==0)
T[p+1]=true;
if(k%2==1)
T[k-1]=true;
p/=2;
k/=2;
}
}
void Query(int n,vector<bool>&V1,vector<bool>&V2,vector<bool>&V3)
{
int result=0;
for(int i=n;i<2*n;i++)
{
int q=i;
bool b1=false,b2=false,b3=false;
while(q>0)
{
if(V1[q]==true)
b1=true;
if(V2[q]==true)
b2=true;
if(V3[q]==true)
b3=true;
q/=2;
}
if(b1==true && b2==true && b3==false)
result++;
}
cout<<result<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
vector<bool>V1(2*n,false),V2(2*n,false),V3(2*n,false);
while(m--)
{
int p,k,t;
cin>>p>>k>>t;
if(t==1)
Update(p,k,n,V1);
else if(t==2)
Update(p,k,n,V2);
else
Update(p,k,n,V3);
}
Query(n,V1,V2,V3);
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 63 64 | #include <bits/stdc++.h> using namespace std; void Update(int p,int k,int n,vector<bool>&T) { p+=n-1; k+=n; T[p]=true; while(p/2!=k/2) { if(p%2==0) T[p+1]=true; if(k%2==1) T[k-1]=true; p/=2; k/=2; } } void Query(int n,vector<bool>&V1,vector<bool>&V2,vector<bool>&V3) { int result=0; for(int i=n;i<2*n;i++) { int q=i; bool b1=false,b2=false,b3=false; while(q>0) { if(V1[q]==true) b1=true; if(V2[q]==true) b2=true; if(V3[q]==true) b3=true; q/=2; } if(b1==true && b2==true && b3==false) result++; } cout<<result<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; vector<bool>V1(2*n,false),V2(2*n,false),V3(2*n,false); while(m--) { int p,k,t; cin>>p>>k>>t; if(t==1) Update(p,k,n,V1); else if(t==2) Update(p,k,n,V2); else Update(p,k,n,V3); } Query(n,V1,V2,V3); return 0; } |
English