#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <array>
using namespace std;
void fastscan(int &x) {
bool neg = false;
int c;
x = 0;
c = getchar();
if (c == '-') {
neg = true;
c = getchar();
}
for (; (c>47 && c<58); c = getchar())
x = (x<<1) + (x<<3) + c - 48;
if (neg) {
x *= -1;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
fastscan(n);
fastscan(m);
vector<array<int, 3>> v(n+1);
while (m--) {
int start, end, color;
fastscan(start);
fastscan(end);
fastscan(color);
v[start-1][color-1]++;
v[end][color-1]--;
}
int res = 0;
if (v[0][0] > 0 && v[0][1] > 0 && v[0][2] == 0) {
res++;
}
for (int i = 1; i < v.size(); i++) {
v[i][0] += v[i-1][0];
v[i][1] += v[i-1][1];
v[i][2] += v[i-1][2];
if (v[i][0] > 0 && v[i][1] > 0 && v[i][2] == 0) {
res++;
}
}
cout << res << endl;
}
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 | #include <iostream> #include <set> #include <vector> #include <algorithm> #include <array> using namespace std; void fastscan(int &x) { bool neg = false; int c; x = 0; c = getchar(); if (c == '-') { neg = true; c = getchar(); } for (; (c>47 && c<58); c = getchar()) x = (x<<1) + (x<<3) + c - 48; if (neg) { x *= -1; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; fastscan(n); fastscan(m); vector<array<int, 3>> v(n+1); while (m--) { int start, end, color; fastscan(start); fastscan(end); fastscan(color); v[start-1][color-1]++; v[end][color-1]--; } int res = 0; if (v[0][0] > 0 && v[0][1] > 0 && v[0][2] == 0) { res++; } for (int i = 1; i < v.size(); i++) { v[i][0] += v[i-1][0]; v[i][1] += v[i-1][1]; v[i][2] += v[i-1][2]; if (v[i][0] > 0 && v[i][1] > 0 && v[i][2] == 0) { res++; } } cout << res << endl; } |
English