#include<bits/stdc++.h>
using namespace std;
int n,x,y,z,K[10][1000005],a;
vector<pair<int,int> > v[10];
pair <int,int> nowy,obecny;
void dodaj(int left,int right, int kolor);
int main()
{
cin >> a >> n;
for (int i = 1 ; i <= n ; i++)
{
cin >> x >> y >> z;
v[z].push_back({x,y});
}
for (int i = 1 ; i <= 3 ; i++)
sort(v[i].begin(),v[i].end());
for (int kolor = 1; kolor <= 3 ; kolor++)
{
obecny = {0,0};
for (int i = 0 ; i < v[kolor].size() ; i++)
{
nowy = {v[kolor][i].first,v[kolor][i].second};
if(obecny.second < nowy.first){
dodaj(obecny.first,obecny.second,kolor);
obecny = nowy;
}
else
obecny.second = max(obecny.second,nowy.second);
}
dodaj(obecny.first,obecny.second,kolor);
}
int w = 0;
for (int i = 1 ; i <= a ; i++)
{
if(K[1][i] >0 && K[2][i] > 0 && K[3][i] == 0)
w++;
}
cout << w;
}
void dodaj(int left,int right, int kolor)
{
// cout << left <<" "<< right <<" "<< kolor <<"\n";
for (int i = left ; i <= right ; i++)
{
K[kolor][i]++;
}
}
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<bits/stdc++.h> using namespace std; int n,x,y,z,K[10][1000005],a; vector<pair<int,int> > v[10]; pair <int,int> nowy,obecny; void dodaj(int left,int right, int kolor); int main() { cin >> a >> n; for (int i = 1 ; i <= n ; i++) { cin >> x >> y >> z; v[z].push_back({x,y}); } for (int i = 1 ; i <= 3 ; i++) sort(v[i].begin(),v[i].end()); for (int kolor = 1; kolor <= 3 ; kolor++) { obecny = {0,0}; for (int i = 0 ; i < v[kolor].size() ; i++) { nowy = {v[kolor][i].first,v[kolor][i].second}; if(obecny.second < nowy.first){ dodaj(obecny.first,obecny.second,kolor); obecny = nowy; } else obecny.second = max(obecny.second,nowy.second); } dodaj(obecny.first,obecny.second,kolor); } int w = 0; for (int i = 1 ; i <= a ; i++) { if(K[1][i] >0 && K[2][i] > 0 && K[3][i] == 0) w++; } cout << w; } void dodaj(int left,int right, int kolor) { // cout << left <<" "<< right <<" "<< kolor <<"\n"; for (int i = left ; i <= right ; i++) { K[kolor][i]++; } } |
English