# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
4551 |
2013-10-27T15:47:37 Z |
ainta |
Tram (CEOI13_tram) |
C++ |
|
51 ms |
3948 KB |
#include<stdio.h>
#include<algorithm>
#include<set>
#define Set_itr set<int>::iterator
#define SetA_itr set<A>::iterator
using namespace std;
set<int>Set;
Set_itr be, ed;
int n, m, dat[31000];
struct A{
int d, r, a, b;
bool operator <(const A &p)const{
return d != p.d ? d < p.d : r > p.r;
}
}tp;
set<A>Set2;
int dist(int a, int b){
int x = a / 2, y = b / 2, r;
if (x < y)r = y - x;
else r = x - y;
r *= 2;
if (a % 2 != b % 2) r++;
if (r == 1)r = 2;
return r;
}
void Print(int a){
printf("%d %d\n", a / 2 + 1, a % 2 + 1);
}
A Sol(Set_itr it){
A res;
Set_itr it2 = it,it3=it,it4;
int y, my, i, t, R = -1, dis, rr;
it2++; it4 = it2;
if (it3 != be)it3--;
if (it4 != ed)it4++;
res.a = *it, res.b = *it2;
y = (res.a / 2 + res.b / 2)/2;
my = y;
if ((res.a / 2 + res.b / 2) & 1)my++;
if (res.b / 2 - res.a / 2 == 2){
y--, my++;
}
while (y <= my){
for (i = 0; i < 2; i++){
t = y * 2 + i;
dis = min(min(dist(t, *it), dist(t, *it2)), min(dist(t, *it3), dist(t, *it4)));
if (R < dis)R = dis, rr = t;
}
y++;
}
res.d = R, res.r = rr;
return res;
}
void Ins(Set_itr it){
if (it != ed){
Set2.insert(Sol(it));
}
if (it != be){
it--;
Set2.insert(Sol(it));
}
}
void Put(int cnt, int t){
dat[cnt] = t;
Print(t);
Set_itr it=Set.lower_bound(t);
if (it != Set.begin() && it != Set.end()){
it--;
Set2.erase(Set2.find(Sol(it)));
}
Set.insert(t);
be = Set.begin();
ed = Set.end();
ed--;
Ins(Set.find(t));
}
void insert(int cnt){
int sz = Set.size(), t, d, r;
Set_itr it = be, it2;
t = 1 - (*it % 2);
if (sz > 1){
it2 = it; it2++;
if (*it2 / 2 == *it / 2)t = 0;
}
d = dist(t, *it), r = t;
it = ed;
t = n * 2 - 1 - (*it % 2);
if (sz > 1){
it2 = it; it2--;
if (*it2 / 2 == *it / 2)t = n * 2 - 2, it = it2;
}
if (d < dist(t, *it))d = dist(t, *it), r = t;
if (Set2.empty()){
Put(cnt, r);
return;
}
SetA_itr iit;
if (!Set2.empty()){
iit = Set2.end(); iit--;
if (iit->d > d || (d == iit->d &&iit->r < r))d = iit->d, r = iit->r;
}
Put(cnt, r);
return;
}
void del(Set_itr it){
if (it != ed){
Set2.erase(Sol(it));
}
if (it != be){
it--;
Set2.erase(Sol(it));
it++;
}
int t = *it;
Set.erase(it);
be = Set.begin();
ed = Set.end(); ed--;
Set_itr it2 = Set.lower_bound(t);
if (it2 != be && it2 != Set.end()){
it2--;
Set2.insert(Sol(it2));
}
}
int main(){
scanf("%d%d", &n, &m);
char pp[2];
int cnt = 0, a;
while (m--){
scanf("%s", pp);
cnt++;
if (!Set.empty()){
be = Set.begin();
ed = Set.end();
ed--;
}
else{
Put(cnt, 0);
continue;
}
if (pp[0] == 'E'){
insert(cnt);
}
else{
scanf("%d", &a);
del(Set.find(dat[a]));
}
}
}
Compilation message
tram.cpp: In function 'int main()':
tram.cpp:125:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
125 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
tram.cpp:129:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
129 | scanf("%s", pp);
| ~~~~~^~~~~~~~~~
tram.cpp:144:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
144 | scanf("%d", &a);
| ~~~~~^~~~~~~~~~
tram.cpp: In function 'A Sol(std::set<int>::iterator)':
tram.cpp:52:9: warning: 'rr' may be used uninitialized in this function [-Wmaybe-uninitialized]
52 | return res;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
492 KB |
Output is correct |
2 |
Runtime error |
2 ms |
628 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
496 KB |
Output is correct |
2 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
2676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
3948 KB |
Output is correct |
2 |
Runtime error |
1 ms |
364 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |