#include <bits/stdc++.h>
using namespace std;
int n, m;
void apply(int l, int r, int k, vector< vector<bool> > &row) {
for(int i = l; i <= r; ++i) {
row[i][k-1] = true;
}
}
vector< vector<bool> > readAndApply() {
int l, r, k;
cin >> n >> m;
vector< vector<bool> > row(n, vector<bool> (3, false));
for(int i = 0; i < m; ++i) {
cin >> l >> r >> k;
apply(l, r, k, row);
}
return row;
}
int solve(vector< vector<bool> > row) {
vector<bool> green(2, true);
green.push_back(false);
int res = 0;
for(int i = 0; i < n; ++i) {
if(row[i] == green)
res++;
}
return res;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
vector< vector<bool> > row = readAndApply();
cout << solve(row) << 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 43 44 45 46 47 48 | #include <bits/stdc++.h> using namespace std; int n, m; void apply(int l, int r, int k, vector< vector<bool> > &row) { for(int i = l; i <= r; ++i) { row[i][k-1] = true; } } vector< vector<bool> > readAndApply() { int l, r, k; cin >> n >> m; vector< vector<bool> > row(n, vector<bool> (3, false)); for(int i = 0; i < m; ++i) { cin >> l >> r >> k; apply(l, r, k, row); } return row; } int solve(vector< vector<bool> > row) { vector<bool> green(2, true); green.push_back(false); int res = 0; for(int i = 0; i < n; ++i) { if(row[i] == green) res++; } return res; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); vector< vector<bool> > row = readAndApply(); cout << solve(row) << endl; return 0; } |
English