1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| class Solution { using LL = long long; public: vector<vector<long long>> splitPainting(vector<vector<int>>& segments) { vector<LL> diff(100001); unordered_map<int, set<int>> m; for (auto &s : segments) { diff[s[0]] += s[2]; diff[s[1]] -= s[2]; m[s[0]].insert(s[2]); } vector<vector<LL>> ans; LL s = 0, prev = 0; for (int i = 0; i < 100001; ++i) if (diff[i] != 0 || (m.count(i) && m[i] != m[i - 1])) { if (prev != 0 && s != 0) ans.push_back({prev, i, s}); s += diff[i]; prev = i; } return ans; } };
|