#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N = (1 << 20);
bool tree[2 * N][3]; // zolty, niebieski, czerwony
int n, m;
void modify(int l, int r, int k) {
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l&1) tree[l++][k] = true;
if (r&1) tree[--r][k] = true;
}
}
bool count(int v, int k) {
v += n;
bool czy = false;
while (v) {
if (tree[v][k]) {
czy = true;
break;
}
v >>= 1;
}
return czy;
}
int main(){
std::ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i ++) {
int l, r, k;
cin >> l >> r >> k;
l --, r --, k --;
modify(l, r + 1, k);
}
int ans = 0;
for (int i = 0; i < n; i ++) {
if (count(i, 0) && count(i, 1) && !count(i, 2)) {
ans ++;
}
}
cout << ans << '\n';
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 | #include <bits/stdc++.h> #define pb push_back #define f first #define s second #define all(x) x.begin(), x.end() using namespace std; typedef long long ll; typedef pair<int,int> pii; const int N = (1 << 20); bool tree[2 * N][3]; // zolty, niebieski, czerwony int n, m; void modify(int l, int r, int k) { for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l&1) tree[l++][k] = true; if (r&1) tree[--r][k] = true; } } bool count(int v, int k) { v += n; bool czy = false; while (v) { if (tree[v][k]) { czy = true; break; } v >>= 1; } return czy; } int main(){ std::ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin >> n >> m; for (int i = 0; i < m; i ++) { int l, r, k; cin >> l >> r >> k; l --, r --, k --; modify(l, r + 1, k); } int ans = 0; for (int i = 0; i < n; i ++) { if (count(i, 0) && count(i, 1) && !count(i, 2)) { ans ++; } } cout << ans << '\n'; return 0; } |
English