# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
659097 |
2022-11-16T14:44:45 Z |
Jeff12345121 |
Tram (CEOI13_tram) |
C++14 |
|
1000 ms |
2300 KB |
#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<pair<int,int>> s;
set<int> dis_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 = dis_s[k - 1].lower_bound(y);
auto before = after;
if (before != dis_s[k - 1].begin()) {
before--;
val[k] = min(val[k], find_distance(k , *before , x, y));
}
if (after != dis_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;
if (s.empty()) {
return {1,1};
}
auto check = [&](int i, int j) {
if (a[i][j] == 0) {
int dis = get_dis(i,j);
if (dis > max_dis) {
max_dis = dis;
sol = {i,j};
} else if (dis == max_dis && (pair<int,int>{i,j}) < sol) {
sol = {i,j};
}
}
};
auto handle = [&](int y1, int y2) {
for (int j = 1; j <= 2; j++) {
check(y1,j);
check(y2,j);
}
/// now check the inbetween spot.
vector<int> mids;
mids.push_back((y1 + y2) / 2);
if ((y1 + y2) %2 == 1) {
mids.push_back((y1 + 2)/2 + 1);
}
for (auto k : mids) {
for (int j = 1; j <= 2; j++) {
check(k,j);
}
}
};
for (auto it = s.begin(); it != s.end(); it++) {
auto nxt = it;
nxt++;
if (nxt != s.end()) {
handle(it->first, nxt->first);
} else {
handle(it->first,n);
}
}
handle(1 , s.begin()->first);
return sol;
}
pair<int,int> i_to_pair(int i) {
int s = 0;
return {i,a[i][1] + 2 * a[i][2]};
}
int main() {
in >> n >> m;
for (int i = 1; i <= m; i++) {
char type;
in >> type;
if (type == 'E') {
pair<int,int> pos = add();
s.erase(i_to_pair(pos.first));
out << pos.first << " " << pos.second << "\n";
a[pos.first][pos.second] = 1;
dis_s[pos.second - 1].insert(pos.first);
s.insert(i_to_pair(pos.first));
queries[i] = pos;
} else {
int pos;
in >> pos;
int y = queries[pos].first,x = queries[pos].second;
s.erase(i_to_pair(y));
dis_s[queries[pos].second - 1].erase(queries[pos].first);
a[y][x] = 0;
if (a[y][1] == 1 || a[y][2] == 1) {
s.insert(i_to_pair(y));
}
}
}
}
Compilation message
tram.cpp: In function 'std::pair<int, int> i_to_pair(int)':
tram.cpp:98:9: warning: unused variable 's' [-Wunused-variable]
98 | int s = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
553 ms |
500 KB |
Output is correct |
2 |
Incorrect |
14 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
541 ms |
464 KB |
Output is correct |
2 |
Incorrect |
15 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
571 ms |
2204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
594 ms |
2300 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1093 ms |
736 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1084 ms |
2192 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |