#pragma GCC optimize ("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; const int INF = 0x3f3f3f3f; #define FOR(i,b,e) for(int i = (b); i < (e); i++) #define TRAV(x,a) for(auto &x: (a)) #define SZ(x) ((int)x.size()) #define PB push_back #define X first #define Y second const int N = 1e6+5; int farb[N][3]; void solve(){ int n, m, ans = 0; cin >> n >> m; FOR(i, 0, m){ int l, r, k; cin >> l >> r >> k; farb[l][k-1]++; farb[r+1][k-1]--; } FOR(i, 1, n+1) FOR(k, 0, 3) farb[i][k] += farb[i-1][k]; FOR(i, 1, n+1) ans += farb[i][0] > 0 && farb[i][1] > 0 && farb[i][2] == 0; cout << ans << '\n'; } int main(){ ios::sync_with_stdio(0); cin.tie(0); solve(); 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 | #pragma GCC optimize ("O3") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; const int INF = 0x3f3f3f3f; #define FOR(i,b,e) for(int i = (b); i < (e); i++) #define TRAV(x,a) for(auto &x: (a)) #define SZ(x) ((int)x.size()) #define PB push_back #define X first #define Y second const int N = 1e6+5; int farb[N][3]; void solve(){ int n, m, ans = 0; cin >> n >> m; FOR(i, 0, m){ int l, r, k; cin >> l >> r >> k; farb[l][k-1]++; farb[r+1][k-1]--; } FOR(i, 1, n+1) FOR(k, 0, 3) farb[i][k] += farb[i-1][k]; FOR(i, 1, n+1) ans += farb[i][0] > 0 && farb[i][1] > 0 && farb[i][2] == 0; cout << ans << '\n'; } int main(){ ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; } |