#include <bits/stdc++.h>
using namespace std;
int a, b, c, n, k, m, licznik, tab[3][2097155];
void Update(int l, int r){
l+=m;
r+=m;
tab[c][l]=true;
if(l!=r) tab[c][r]=true;
while(l/2!=r/2){
if(l%2==0) tab[c][l+1]=true;
if(r%2==1) tab[c][r-1]=true;
l/=2;
r/=2;
}
}
int Query(int x, int y){
x+=m;
int suma=0;
while(x>0){
suma+=tab[y][x];
x/=2;
}
return suma;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);
cin >> n >> k;
m=1;
while(m<n) m*=2;
for(int i=0; i<k; i++){
cin >> a >> b >> c;
c--;
Update(a, b);
}
for(int i=1; i<=n; i++) if(Query(i, 0)!=0 && Query(i, 1)!=0 && Query(i,2)==0) licznik++;
cout << licznik;
}
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 | #include <bits/stdc++.h> using namespace std; int a, b, c, n, k, m, licznik, tab[3][2097155]; void Update(int l, int r){ l+=m; r+=m; tab[c][l]=true; if(l!=r) tab[c][r]=true; while(l/2!=r/2){ if(l%2==0) tab[c][l+1]=true; if(r%2==1) tab[c][r-1]=true; l/=2; r/=2; } } int Query(int x, int y){ x+=m; int suma=0; while(x>0){ suma+=tab[y][x]; x/=2; } return suma; } int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> n >> k; m=1; while(m<n) m*=2; for(int i=0; i<k; i++){ cin >> a >> b >> c; c--; Update(a, b); } for(int i=1; i<=n; i++) if(Query(i, 0)!=0 && Query(i, 1)!=0 && Query(i,2)==0) licznik++; cout << licznik; } |
English