#include<iostream>
#include<vector>
#include<string>
#include<queue>
using namespace std;
const int max_n = 1e6 + 3;
int colour[max_n][3];
//g++ -O3 -static 1B/1B.cpp -std=c++11 -o 1B/1b
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++){
int l, r, k;
cin >> l >> r >> k;
colour[l - 1][k - 1] ++;
colour[r][k - 1] --;
}
int c[3] = {0, 0, 0};
int green = 0;
// cout << "DEBUG" << endl;
// for(int i = 0; i < n; i++){
// for(int j = 0; j < 3; j++){
// cout << " " << colour[i][j];
// }
// cout << endl;
// }
// cout << "END DEBUG" << endl;
for(int i = 0; i < n; i++){
for(int j = 0; j < 3; j++){
c[j] += colour[i][j];
}
if(c[0] > 0 && c[1] > 0 && c[2] == 0){
green ++;
}
}
cout << green;
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 | #include<iostream> #include<vector> #include<string> #include<queue> using namespace std; const int max_n = 1e6 + 3; int colour[max_n][3]; //g++ -O3 -static 1B/1B.cpp -std=c++11 -o 1B/1b int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for(int i = 0; i < m; i++){ int l, r, k; cin >> l >> r >> k; colour[l - 1][k - 1] ++; colour[r][k - 1] --; } int c[3] = {0, 0, 0}; int green = 0; // cout << "DEBUG" << endl; // for(int i = 0; i < n; i++){ // for(int j = 0; j < 3; j++){ // cout << " " << colour[i][j]; // } // cout << endl; // } // cout << "END DEBUG" << endl; for(int i = 0; i < n; i++){ for(int j = 0; j < 3; j++){ c[j] += colour[i][j]; } if(c[0] > 0 && c[1] > 0 && c[2] == 0){ green ++; } } cout << green; return 0; } |
English