#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 1000 * 1000 + 10;
int n, m;
int t[nax][3];
bool col[nax][3];
int main() {_
cin >> n >> m;
while(m--) {
int a, b, k;
cin >> a >> b >> k;
k--;
t[a][k]++;
t[b + 1][k]--;
}
for(int k = 0; k < 3; ++k) {
int cur = 0;
for(int i = 1; i <= n; ++i) {
cur += t[i][k];
col[i][k] = (cur > 0);
}
}
int ans = 0;
for(int i = 1; i <= n; ++i) {
if(col[i][0] && col[i][1] && (!col[i][2])) ans++;
}
cout << ans;
}
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 | #include <bits/stdc++.h> #define PB push_back #define ST first #define ND second #define _ ios_base::sync_with_stdio(0); cin.tie(0); //mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); using namespace std; using ll = long long; using pi = pair<int,int>; using vi = vector<int>; const int nax = 1000 * 1000 + 10; int n, m; int t[nax][3]; bool col[nax][3]; int main() {_ cin >> n >> m; while(m--) { int a, b, k; cin >> a >> b >> k; k--; t[a][k]++; t[b + 1][k]--; } for(int k = 0; k < 3; ++k) { int cur = 0; for(int i = 1; i <= n; ++i) { cur += t[i][k]; col[i][k] = (cur > 0); } } int ans = 0; for(int i = 1; i <= n; ++i) { if(col[i][0] && col[i][1] && (!col[i][2])) ans++; } cout << ans; } |
English