#include <bits/stdc++.h>
using namespace std;
#define bit(n, i) ((n>>i) & 1)
#define fi first
#define se second
#define pb push_back
#define cat(x) cerr << #x " = " << x << "\n"
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
const int N = 1e6+9;
int cnt[N][3];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m; cin >> n >> m;
for(int i = 1; i <= m; ++i) {
int l, r, k; cin >> l >> r >> k;
cnt[l][k-1]++;
cnt[r+1][k-1]--;
}
int res = 0;
for(int i = 1; i <= n; ++i) {
cnt[i][0] += cnt[i-1][0];
cnt[i][1] += cnt[i-1][1];
cnt[i][2] += cnt[i-1][2];
if(cnt[i][0] >= 1 && cnt[i][1] >= 1 && cnt[i][2] == 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 | #include <bits/stdc++.h> using namespace std; #define bit(n, i) ((n>>i) & 1) #define fi first #define se second #define pb push_back #define cat(x) cerr << #x " = " << x << "\n" using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using ld = long double; const int N = 1e6+9; int cnt[N][3]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; for(int i = 1; i <= m; ++i) { int l, r, k; cin >> l >> r >> k; cnt[l][k-1]++; cnt[r+1][k-1]--; } int res = 0; for(int i = 1; i <= n; ++i) { cnt[i][0] += cnt[i-1][0]; cnt[i][1] += cnt[i-1][1]; cnt[i][2] += cnt[i-1][2]; if(cnt[i][0] >= 1 && cnt[i][1] >= 1 && cnt[i][2] == 0) res++; } cout << res; return 0; } |
English