#include <bits/stdc++.h>
using namespace std;
void solve (int n, int L, vector <vector <bool> >& t, vector <vector <bool> >& tp)
{
int l, r, k;
cin >> l >> r >> k;
--l;
--k;
while (l % L != 0 && l < r)
{
t[l][k] = true;
l++;
}
while (l + L <= r)
{
tp[l/L][k] = true;
l += L;
}
while (l < r)
{
t[l][k] = true;
l++;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
int L = sqrt(n);
if (L*L != n) ++L;
vector <vector <bool> > t (n+1, vector <bool>(3));
vector <vector <bool> > tp (L+1, vector <bool>(3));
while (m--)
solve(n, L, t, tp);
int res = 0;
for (int i = 0; i < n; ++i)
{
if (!t[i][2] && !tp[i/L][2] && (t[i][1] || tp[i/L][1]) && (t[i][0] || tp[i/L][0]))
++res;
}
cout << res;
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 | #include <bits/stdc++.h> using namespace std; void solve (int n, int L, vector <vector <bool> >& t, vector <vector <bool> >& tp) { int l, r, k; cin >> l >> r >> k; --l; --k; while (l % L != 0 && l < r) { t[l][k] = true; l++; } while (l + L <= r) { tp[l/L][k] = true; l += L; } while (l < r) { t[l][k] = true; l++; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; int L = sqrt(n); if (L*L != n) ++L; vector <vector <bool> > t (n+1, vector <bool>(3)); vector <vector <bool> > tp (L+1, vector <bool>(3)); while (m--) solve(n, L, t, tp); int res = 0; for (int i = 0; i < n; ++i) { if (!t[i][2] && !tp[i/L][2] && (t[i][1] || tp[i/L][1]) && (t[i][0] || tp[i/L][0])) ++res; } cout << res; return 0; } |
English