Submission #1119815

#TimeUsernameProblemLanguageResultExecution timeMemory
1119815Tenis0206Text editor (CEOI24_editor)C++11
0 / 100
78 ms103756 KiB
#include <bits/stdc++.h> using namespace std; const int nmax = 2e5; struct punct { int x, y; char dir; }; int n; punct v[nmax + 5]; int sel[nmax + 5]; int cnt; struct diag { bool is_built; priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>>> H; multiset<pair<int,pair<int,int>>> s; bool Empty() { return H.empty(); } pair<int,pair<int,int>> Top() { return H.top(); } void add(int i, int x, int tip) { s.insert({x, {tip, i}}); } void build() { if(is_built) { return; } is_built = true; int last = 0; int last_x = 0; int last_tip = -1; for(auto it=s.begin();it!=s.end();it++) { if(last_tip == 0 && it -> second.first == 1) { H.push({it->first - last_x, {last, it->second.second}}); } last = it->second.second; last_x = it->first; last_tip = it->second.first; } } void rem(int i, int x, int tip) { auto er = s.lower_bound({x, {tip, i}}); auto u = s.upper_bound({x, {tip, i}}); if(er != s.begin() && u != s.end()) { auto p = er; p--; if(p -> second.first == 0 && u -> second.first == 1) { H.push({u->first - p->first, {p->second.second, u->second.second}}); } } s.erase(er); while(!H.empty() && (sel[H.top().second.first] || sel[H.top().second.second])) { H.pop(); } } }; diag dne[nmax + 5], dnv[nmax + 5], dse[nmax + 5], dsv[nmax + 5], dns[nmax + 5], dve[nmax + 5]; priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>, greater<pair<int,pair<int,int>>>> h; vector<int> d0, d1; vector<int> dx, dy; int get_val(vector<int> &a, int val) { int st = 1; int dr = a.size(); int poz = 0; while(st <= dr) { int mij = (st + dr) >> 1; if(a[mij - 1] <= val) { poz = mij; st = mij + 1; } else { dr = mij - 1; } } return poz; } void Add(int i) { int diag0 = get_val(d0, v[i].x - v[i].y); int diag1 = get_val(d1, v[i].x + v[i].y); if(v[i].dir == 'N') { dne[diag0].add(i, v[i].x, 1); dnv[diag1].add(i, v[i].x, 0); } else if(v[i].dir == 'S') { dsv[diag0].add(i, v[i].x, 0); dse[diag1].add(i, v[i].x, 1); } else if(v[i].dir == 'E') { dne[diag0].add(i, v[i].x, 0); dse[diag1].add(i, v[i].x, 0); } else if(v[i].dir == 'W') { dsv[diag0].add(i, v[i].x, 1); dnv[diag1].add(i, v[i].x, 1); } int px = get_val(dx, v[i].x); int py = get_val(dy, v[i].y); if(v[i].dir == 'N') { dns[px].add(i, v[i].y / 2, 1); } else if(v[i].dir == 'S') { dns[px].add(i, v[i].y / 2, 0); } else if(v[i].dir == 'E') { dve[py].add(i, v[i].x / 2, 0); } else if(v[i].dir == 'W') { dve[py].add(i, v[i].x / 2, 1); } } void Build(int i) { int diag0 = get_val(d0, v[i].x - v[i].y); int diag1 = get_val(d1, v[i].x + v[i].y); if(v[i].dir == 'N') { dne[diag0].build(); dnv[diag1].build(); if(!dne[diag0].Empty()) { h.push(dne[diag0].Top()); } if(!dnv[diag1].Empty()) { h.push(dnv[diag1].Top()); } } else if(v[i].dir == 'S') { dsv[diag0].build(); dse[diag1].build(); if(!dsv[diag0].Empty()) { h.push(dsv[diag0].Top()); } if(!dse[diag1].Empty()) { h.push(dse[diag1].Top()); } } else if(v[i].dir == 'E') { dne[diag0].build(); dse[diag1].build(); if(!dne[diag0].Empty()) { h.push(dne[diag0].Top()); } if(!dse[diag1].Empty()) { h.push(dse[diag1].Top()); } } else if(v[i].dir == 'W') { dsv[diag0].build(); dnv[diag1].build(); if(!dsv[diag0].Empty()) { h.push(dsv[diag0].Top()); } if(!dnv[diag1].Empty()) { h.push(dnv[diag1].Top()); } } int px = get_val(dx, v[i].x); int py = get_val(dy, v[i].y); if(v[i].dir == 'N') { dns[px].build(); if(!dns[px].Empty()) { h.push(dns[px].Top()); } } else if(v[i].dir == 'S') { dns[px].build(); if(!dns[px].Empty()) { h.push(dns[px].Top()); } } else if(v[i].dir == 'E') { dve[py].build(); if(!dve[py].Empty()) { h.push(dve[py].Top()); } } else if(v[i].dir == 'W') { dve[py].build(); if(!dve[py].Empty()) { h.push(dve[py].Top()); } } } void Remove(int i) { if(sel[i]) { return; } sel[i] = cnt; int diag0 = get_val(d0, v[i].x - v[i].y); int diag1 = get_val(d1, v[i].x + v[i].y); if(v[i].dir == 'N') { dne[diag0].rem(i, v[i].x, 1); dnv[diag1].rem(i, v[i].x, 0); if(!dne[diag0].Empty()) { h.push(dne[diag0].Top()); } if(!dnv[diag1].Empty()) { h.push(dnv[diag1].Top()); } } else if(v[i].dir == 'S') { dsv[diag0].rem(i, v[i].x, 0); dse[diag1].rem(i, v[i].x, 1); if(!dsv[diag0].Empty()) { h.push(dsv[diag0].Top()); } if(!dse[diag1].Empty()) { h.push(dse[diag1].Top()); } } else if(v[i].dir == 'E') { dne[diag0].rem(i, v[i].x, 0); dse[diag1].rem(i, v[i].x, 0); if(!dne[diag0].Empty()) { h.push(dne[diag0].Top()); } if(!dse[diag1].Empty()) { h.push(dse[diag1].Top()); } } else if(v[i].dir == 'W') { dsv[diag0].rem(i, v[i].x, 1); dnv[diag1].rem(i, v[i].x, 1); if(!dsv[diag0].Empty()) { h.push(dsv[diag0].Top()); } if(!dnv[diag1].Empty()) { h.push(dnv[diag1].Top()); } } int px = get_val(dx, v[i].x); int py = get_val(dy, v[i].y); if(v[i].dir == 'N') { dns[px].rem(i, v[i].y / 2, 1); if(!dns[px].Empty()) { h.push(dns[px].Top()); } } else if(v[i].dir == 'S') { dns[px].rem(i, v[i].y / 2, 0); if(!dns[px].Empty()) { h.push(dns[px].Top()); } } else if(v[i].dir == 'E') { dve[py].rem(i, v[i].x / 2, 0); if(!dve[py].Empty()) { h.push(dve[py].Top()); } } else if(v[i].dir == 'W') { dve[py].rem(i, v[i].x / 2, 1); if(!dve[py].Empty()) { h.push(dve[py].Top()); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); #ifdef home freopen("nr.in","r",stdin); freopen("nr.out","w",stdout); #endif // home cin>>n; for(int i=1; i<=n; i++) { cin>>v[i].x>>v[i].y>>v[i].dir; d0.push_back(v[i].x - v[i].y); d1.push_back(v[i].x + v[i].y); dx.push_back(v[i].x); dy.push_back(v[i].y); } sort(d0.begin(),d0.end()); sort(d1.begin(),d1.end()); for(int i=1; i<=n; i++) { Add(i); } for(int i=1;i<=n;i++) { Build(i); } while(!h.empty()) { ++cnt; while(!h.empty() && (sel[h.top().second.first] || sel[h.top().second.second])) { h.pop(); } if(h.empty()) { break; } int val = h.top().first; while(!h.empty() && h.top().first == val) { if(!sel[h.top().second.first] && !sel[h.top().second.second]) { Remove(h.top().second.first); Remove(h.top().second.second); } else if(!sel[h.top().second.first] && sel[h.top().second.second] == cnt) { Remove(h.top().second.first); } else if(sel[h.top().second.first] == cnt && !sel[h.top().second.second]) { Remove(h.top().second.second); } h.pop(); } } for(int i=1;i<=n;i++) { if(!sel[i]) { cout<<i<<'\n'; } } return 0; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...