Submission #837055

#TimeUsernameProblemLanguageResultExecution timeMemory
837055Nicolas125841Plahte (COCI17_plahte)C++17
0 / 160
2051 ms188728 KiB
#include <bits/stdc++.h> using namespace std; struct Container { int index; set<int>* colors; Container* parent; vector<Container*> children; Container(Container* p, int i): parent(p), index(i) { colors = new set<int>(); } }; struct Event { int index; int color; int x_pos; int y_low, y_high; bool close; Event(int col, int x, int yl, int yh, bool c, int i): color(col), x_pos(x), y_low(yl), y_high(yh), close(c), index(i) {} }; struct Node { Node *l = 0, *r = 0; int lo, hi; Container* mset = NULL; Container* val = NULL; Node(int lo,int hi): lo(lo), hi(hi) {} Container* query(int L, int R) { if (R <= lo || hi <= L) return NULL; if (L <= lo && hi <= R) return val; push(); Container* result; if((result = l->query(L, R)) != NULL) return result; else if((result = r->query(L, R)) != NULL) return result; else return NULL; } void set(int L, int R, Container* x) { if (R <= lo || hi <= L) return; if (L <= lo && hi <= R) mset = val = x; else { push(), l->set(L, R, x), r->set(L, R, x); } } void push() { if (!l) { int mid = lo + (hi - lo)/2; l = new Node(lo, mid); r = new Node(mid, hi); } if (mset != NULL) l->set(lo,hi,mset), r->set(lo,hi,mset), mset = NULL; } }; void resolve(Container* node, vector<int> &colorCounts){ for(Container* child : node->children){ resolve(child, colorCounts); node->colors->merge(*(child->colors)); } if(node->index != -1) colorCounts[node->index] = node->colors->size(); } int main(){ cin.tie(NULL)->sync_with_stdio(false); int n, m; cin >> n >> m; vector<Event> actions; for(int i = 0; i < n; i++){ int lx, ly, ux, uy; cin >> lx >> ly >> ux >> uy; actions.emplace_back(-1, lx, ly, uy, false, i); actions.emplace_back(-1, ux, ly, uy, true, i); } for(int i = 0; i < m; i++){ int x, y, c; cin >> x >> y >> c; actions.emplace_back(c, x, y, y, true, i); } auto actionComp = [](const auto &a, const auto &b){ if(a.x_pos == b.x_pos){ if(a.color == -1 && b.color == -1) return a.y_low < b.y_low; else if(a.color == -1 && b.color != -1) return !b.close; else if(a.color != -1 && b.color == -1) return b.close; else return a.y_low < b.y_low; }else return a.x_pos < b.x_pos; }; sort(actions.begin(), actions.end(), actionComp); Container root(NULL, -1); Node* containerQuery = new Node(-10, 1e9+10); containerQuery->set(0, (1e9 + 1) + 1, &root); for(const Event event : actions){ if(event.color == -1){ if(event.close){ Container* child = containerQuery->query(event.y_low, event.y_high + 1); // cout << "Closing: " << child->index << "\n"; containerQuery->set(event.y_low, event.y_high + 1, child->parent); }else{ Container* parent = containerQuery->query(event.y_low, event.y_high + 1); parent->children.push_back(new Container(parent, event.index)); // cout << "Opening: " << event.index << "\n"; containerQuery->set(event.y_low, event.y_high + 1, parent->children.back()); } }else{ Container* sheet = containerQuery->query(event.y_low, event.y_high + 1); // cout << "Inserting into: " << sheet->index << "\n"; sheet->colors->insert(event.color); } } vector<int> colorCounts(n, 0); resolve(&root, colorCounts); for(const int &count : colorCounts) cout << count << "\n"; }

Compilation message (stderr)

plahte.cpp: In constructor 'Container::Container(Container*, int)':
plahte.cpp:8:16: warning: 'Container::parent' will be initialized after [-Wreorder]
    8 |     Container* parent;
      |                ^~~~~~
plahte.cpp:6:9: warning:   'int Container::index' [-Wreorder]
    6 |     int index;
      |         ^~~~~
plahte.cpp:11:5: warning:   when initialized here [-Wreorder]
   11 |     Container(Container* p, int i): parent(p), index(i) {
      |     ^~~~~~~~~
plahte.cpp: In constructor 'Event::Event(int, int, int, int, bool, int)':
plahte.cpp:21:10: warning: 'Event::close' will be initialized after [-Wreorder]
   21 |     bool close;
      |          ^~~~~
plahte.cpp:17:9: warning:   'int Event::index' [-Wreorder]
   17 |     int index;
      |         ^~~~~
plahte.cpp:23:5: warning:   when initialized here [-Wreorder]
   23 |     Event(int col, int x, int yl, int yh, bool c, int i):
      |     ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...