#include<bits/stdc++.h>
using namespace std;
#define upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int lim=(1<<20);
int n, m;
struct kolory
{
bool zolty, niebieski, czerwony;
};
kolory beczki[lim<<1];
void updateRange(int node, int start, int en, int l, int r, int id)
{
if(start > en || start > r || en < l)
return;
if(start >= l && en <= r)
{
if(id==1)
beczki[node].zolty=true;
else if(id==2)
beczki[node].niebieski=true;
else
beczki[node].czerwony=true;
return;
}
int mid = (start + en) / 2;
updateRange(node*2, start, mid, l, r, id);
updateRange(node*2 + 1, mid + 1, en, l, r, id);
}
bool queryPoint(int index, int id)
{
index+=lim;
if(id==1)
{
if(beczki[index].zolty)
return true;
while(index!=1)
{
index/=2;
if(beczki[index].zolty)
return true;
}
return false;
}
else if(id==2)
{
if(beczki[index].niebieski)
return true;
while(index!=1)
{
index/=2;
if(beczki[index].niebieski)
return true;
}
return false;
}
else
{
if(beczki[index].czerwony)
return true;
while(index!=1)
{
index/=2;
if(beczki[index].czerwony)
return true;
}
return false;
}
}
int main()
{
upgrade
cin>>n>>m;
for(int i=0;i<m;i++)
{
int a, b, c;
cin>>a>>b>>c;
a--, b--;
updateRange(1, 0, lim-1, a, b, c);
}
int ans=0;
for(int i=0;i<n;i++)
ans+=(!queryPoint(i, 3) && (queryPoint(i, 1) && queryPoint(i, 2)));
cout<<ans;
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 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 | #include<bits/stdc++.h> using namespace std; #define upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); const int lim=(1<<20); int n, m; struct kolory { bool zolty, niebieski, czerwony; }; kolory beczki[lim<<1]; void updateRange(int node, int start, int en, int l, int r, int id) { if(start > en || start > r || en < l) return; if(start >= l && en <= r) { if(id==1) beczki[node].zolty=true; else if(id==2) beczki[node].niebieski=true; else beczki[node].czerwony=true; return; } int mid = (start + en) / 2; updateRange(node*2, start, mid, l, r, id); updateRange(node*2 + 1, mid + 1, en, l, r, id); } bool queryPoint(int index, int id) { index+=lim; if(id==1) { if(beczki[index].zolty) return true; while(index!=1) { index/=2; if(beczki[index].zolty) return true; } return false; } else if(id==2) { if(beczki[index].niebieski) return true; while(index!=1) { index/=2; if(beczki[index].niebieski) return true; } return false; } else { if(beczki[index].czerwony) return true; while(index!=1) { index/=2; if(beczki[index].czerwony) return true; } return false; } } int main() { upgrade cin>>n>>m; for(int i=0;i<m;i++) { int a, b, c; cin>>a>>b>>c; a--, b--; updateRange(1, 0, lim-1, a, b, c); } int ans=0; for(int i=0;i<n;i++) ans+=(!queryPoint(i, 3) && (queryPoint(i, 1) && queryPoint(i, 2))); cout<<ans; return 0; } |
English