#include <vector>
#include <cstdio>
#include <algorithm>
#define YELLOW 0
using namespace std;
struct Range {
int start;
int end;
Range() {
this->start = 1000000000;
this->end = 1000000000;
}
Range(int start, int end) {
this->start = start;
this->end = end;
}
};
bool range_cmp(Range A, Range B) {
return A.start < B.start;
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
vector<vector<Range>> colors(3);
vector<vector<bool>> painted(3);
for (int i=0; i<3; i++) {
colors[i].resize(m);
painted[i].resize(n, false);
}
int amounts[3] = {0, 0, 0};
for (int i=0; i<m; i++) {
int l, r, k;
scanf("%d %d %d", &l, &r, &k);
k--;
l--;
r--;
colors[k][amounts[k]] = Range(l, r);
amounts[k]++;
}
for (int i=0; i<3; i++) {
colors[i].resize(amounts[i]);
sort(colors[i].begin(), colors[i].end(), range_cmp);
int last_idx = 0;
for (int j=0; j<colors[i].size(); j++) {
int start = 1000000000;
if (last_idx >= colors[i][j].start && last_idx < colors[i][j].end) {
start = last_idx;
} else if (last_idx < colors[i][j].start) {
start = colors[i][j].start;
}
for (int k=start; k<=colors[i][j].end; k++) {
painted[i][k] = true;
last_idx = k;
}
}
}
int result = 0;
for (int i=0; i<n; i++) {
// printf("%s %s %s\n", painted[0][i]?"true":"false", painted[1][i]?"true":"false", painted[2][i]?"true":"false");
if (painted[0][i] && painted[1][i] && !painted[2][i]) {
result++;
}
}
printf("%d", result);
}
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #include <vector> #include <cstdio> #include <algorithm> #define YELLOW 0 using namespace std; struct Range { int start; int end; Range() { this->start = 1000000000; this->end = 1000000000; } Range(int start, int end) { this->start = start; this->end = end; } }; bool range_cmp(Range A, Range B) { return A.start < B.start; } int main() { int n, m; scanf("%d %d", &n, &m); vector<vector<Range>> colors(3); vector<vector<bool>> painted(3); for (int i=0; i<3; i++) { colors[i].resize(m); painted[i].resize(n, false); } int amounts[3] = {0, 0, 0}; for (int i=0; i<m; i++) { int l, r, k; scanf("%d %d %d", &l, &r, &k); k--; l--; r--; colors[k][amounts[k]] = Range(l, r); amounts[k]++; } for (int i=0; i<3; i++) { colors[i].resize(amounts[i]); sort(colors[i].begin(), colors[i].end(), range_cmp); int last_idx = 0; for (int j=0; j<colors[i].size(); j++) { int start = 1000000000; if (last_idx >= colors[i][j].start && last_idx < colors[i][j].end) { start = last_idx; } else if (last_idx < colors[i][j].start) { start = colors[i][j].start; } for (int k=start; k<=colors[i][j].end; k++) { painted[i][k] = true; last_idx = k; } } } int result = 0; for (int i=0; i<n; i++) { // printf("%s %s %s\n", painted[0][i]?"true":"false", painted[1][i]?"true":"false", painted[2][i]?"true":"false"); if (painted[0][i] && painted[1][i] && !painted[2][i]) { result++; } } printf("%d", result); } |
English