제출 #385314

#제출 시각아이디문제언어결과실행 시간메모리
385314mohamedsobhi777전차 (CEOI13_tram)C++14
0 / 100
1079 ms1260 KiB
#include <bits/stdc++.h> using namespace std; #define vi vector<int> #define vll vector<ll> #define vii vector<pair<int, int>> #define pii pair<int, int> #define pll pair<ll, ll> #define loop(_) for (int __ = 0; __ < (_); ++__) #define pb push_back #define f first #define s second #define sz(_) ((int)_.size()) #define all(_) _.begin(), _.end() #define lb lower_bound #define ub upper_bound using ll = long long; using ld = long double; const int N = 1e5 + 7; const ll mod = 1e9 + 7; int n, m; int vis[N][2]; int xs[N], ys[N]; multiset<int> mul; struct cmp { bool operator()(pii x, pii y) { return x.s - x.f != y.s - y.f ? x.s - x.f > y.s - y.f : x.f < y.f; } }; set<pii, cmp> st; set<pii> rst; int calc(int x, int y) { int ret = 1e9; if (mul.empty()) return ret; auto eval = [&](int u) -> void { for (int i = 0; i < 2; ++i) { if (vis[u][i]) { ret = min(ret, (u - x) * (u - x) + (i - y) * (i - y)); } } }; auto it = mul.lb(x); if (it != mul.end()) eval(*it); if (it != mul.begin()) eval(*(--it)); return ret; } void Insert(int x, int y) { st.insert({x, y}); rst.insert({x, y}); } void Erase(int x, int y) { st.erase({x, y}); rst.erase({x, y}); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE #endif cin >> n >> m; Insert(0, n - 1); for (int i = 0; i < m; ++i) { char c; cin >> c; if (c == 'E') { int Min = 0; int wx = 0, wy = 0; if (sz(mul) >= 2 && sz(rst)) { for (auto u : st) { int x = u.f, y = u.s; int mid = (x + y) >> 1; for (int i = 0; i < 2; ++i) { int w = calc(mid, i); if (w > Min) { Min = w; wx = mid, wy = i; } } // cout << x << "+" << y << "*\n"; } // exit(0); } else if (!sz(rst)) { wx = sz(mul) - n; wy = calc(wx, 1) > calc(wx, 0); } else if (sz(mul) == 1) wx = n - 1, wy = 1; xs[i] = wx, ys[i] = wy; vis[wx][wy] = 1; for (auto u : st) { if (wx >= u.f && wx <= u.s) { int x = u.f, y = u.s; Erase(x, y); if (x <= wx - 1) Insert(x, wx - 1); if (wx + 1 <= y) Insert(wx + 1, y); break; } } mul.insert(wx); cout << ++wx << " " << ++wy << "\n"; } else { int p; cin >> p; --p; mul.erase(mul.find(xs[p])); vis[xs[p]][ys[p]] = 0; if (vis[xs[p]][0] == vis[xs[p]][1]) { // for(auto u : rst)cout << u.f <<" " << u.s <<"++\n" ; auto it = rst.lb({xs[p], -1}); int nxt = (it != rst.end() ? (*it).s : n - 1); if (it != rst.end()) { Erase((*it).f, (*it).s); } // cout <<"Erase " << xs[p] <<" " << ys[p] <<" now \n" ; --it; int prv = (*it).f; // cout << prv <<" " << nxt <<"#\n"; Erase((*it).f, (*it).s); Insert(prv, nxt); // for(auto u : rst)cout << u.f <<" " << u.s <<"()\n" ; // exit(0) ; } } } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...