gt22

Untitled

Oct 11th, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <vector>
  2. #include "optimization.h"
  3. #include <tuple>
  4. using namespace std;
  5.  
  6. vector<int> c, p;
  7. int n;
  8. int paint(int l, int r, int color) {
  9.     if(l > r || l >= n || l < 0) {
  10.         return l;
  11.     }
  12.     if(c[l] == -1) c[l] = color;
  13.     return p[l] = paint(p[l], r, color);
  14. }
  15.  
  16. int main() {
  17.     n = readInt();
  18.     int k = readInt();
  19.     int m = readInt();
  20.     vector<tuple<int, int, int>> q(m);
  21.     for (int i = 0; i < m; ++i) {
  22.         q[i] = {readInt() - 1, readInt() - 1, readInt() - 1};
  23.     }
  24.     c.resize(n, -1);
  25.     p.resize(n, 0);
  26.     for (int i = 0; i < n; ++i) {
  27.         p[i] = i + 1;
  28.     }
  29.     for (auto i = m - 1; i >= 0; i--) {
  30.         auto [cc, l, r] = q[i];
  31.         paint(l, r, cc);
  32.     }
  33.     vector<int> count(k);
  34.     for(int cc : c) {
  35.         count[cc]++;
  36.     }
  37.     for (int cc : count) {
  38.         writeInt(cc, ' ');
  39.     }
  40.     writeChar('\n');
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment