Submission #659088

#TimeUsernameProblemLanguageResultExecution timeMemory
659088Jeff12345121Tram (CEOI13_tram)C++14
45 / 100
1090 ms1036 KiB
#include <bits/stdc++.h> #define REP(i,n) for(int i = 1; i <= (n); i++) using namespace std; #ifdef LOCAL ifstream in("in.in"); ofstream out("out.out"); #else #define in cin #define out cout #endif ///brute int n,m; const int nmax = 150005,inf = 1000000005; pair<int,int> queries[nmax]; int a[nmax][3]; set<int> s[2]; int squared(int x) { return x * x; } int find_distance(int y, int x, int i, int j) { return squared(y - i) + squared(x - j); } int get_dis(int y, int x) { int val[3] = {inf,inf,inf};///min dis from some other value for (int k = 1; k <= 2; k++) { auto after = s[k - 1].lower_bound(y); auto before = after; if (before != s[k - 1].begin()) { before--; val[k] = min(val[k], find_distance(k , *before , x, y)); } if (after != s[k - 1].end()) { val[k] = min(val[k], find_distance(k , *after , x, y)); } } return min(val[1] ,val[2]); } pair<int,int> add() { pair<int,int> sol; int max_dis = -inf; for (int i = 1; i <= n; i++) { for (int j = 1; j <= 2; j++) { if (a[i][j] == 1) continue; int dis = get_dis(i,j); if (dis > max_dis) { max_dis = dis; sol = {i,j}; } } } return sol; } int main() { in >> n >> m; for (int i = 1; i <= m; i++) { char type; in >> type; if (type == 'E') { pair<int,int> pos = add(); out << pos.first << " " << pos.second << "\n"; a[pos.first][pos.second] = 1; s[pos.second - 1].insert(pos.first); queries[i] = pos; } else { int pos; in >> pos; s[queries[pos].second - 1].erase(queries[pos].first); a[queries[pos].first][queries[pos].second] = 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...