lc 1943. 描述绘画结果
就是个差分数组,注意保存一下每个点的颜色即可
class Solution { public: long long d[100010]; vector<vector<long long > > ret; vector<vector<long long>> splitPainting(vector<vector<int>>& segments) { memset(d, 0, sizeof(d)); int cnt = 0; set<string> s[100010]; vector<long long > t; int length = segments.size(); int low = 100010; for(int i = 0; i < length; i++) { d[segments[i][0]] += segments[i][2]; d[segments[i][1]] -= segments[i][2]; low = min(low, segments[i][0]); s[segments[i][0]].insert(to_string(segments[i][2])); s[segments[i][1]].insert(to_string(segments[i][2])); } int p = low; long long color = d[1], k = d[low]; for(int i = low + 1; i <= 100000; i++) { t.clear(); if(k + d[i] == k) { if(s[i].size() == 0 || (s[p].size() != 0 && s[i] == s[p])) k += d[i]; else { if(k == 0) continue; t.push_back(p); t.push_back(i); t.push_back(k); ret.push_back(t); k += d[i]; p = i; } } else { if(k != 0) { t.push_back(p); t.push_back(i); t.push_back(k); ret.push_back(t); } k += d[i]; p = i; } } return ret; } };
自己选择的路,跪着也要走完。朋友们,虽然这个世界日益浮躁起来,只要能够为了当时纯粹的梦想和感动坚持努力下去,不管其它人怎么样,我们也能够保持自己的本色走下去。