#include <iostream> using namespace std; int sol() { int res = 0; int n, m; cin>>n>>m; int A[n][3] = {0}; for(int i = 0; i < m; i++) { int from, to, color; cin>>from>>to>>color; from--; to--; color--; for(int j = from; j <= to; j++) { A[j][color]++; } } for(int i = 0; i < n; i++) { if(A[i][0] >= 1 && A[i][1] >= 1 && A[i][2] ==0) res++; } return res; } int main() { cout<<sol()<<endl; 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 | #include <iostream> using namespace std; int sol() { int res = 0; int n, m; cin>>n>>m; int A[n][3] = {0}; for(int i = 0; i < m; i++) { int from, to, color; cin>>from>>to>>color; from--; to--; color--; for(int j = from; j <= to; j++) { A[j][color]++; } } for(int i = 0; i < n; i++) { if(A[i][0] >= 1 && A[i][1] >= 1 && A[i][2] ==0) res++; } return res; } int main() { cout<<sol()<<endl; return 0; } |