이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
#include<list>
#include<algorithm>
struct ant {
int x;
int d;
ant(int x, int d) :x(x), d(d) {}
bool operator<(const ant& p)const {
return x < p.x;
}
bool operator>(const ant& p)const {
return x > p.x;
}
};
std::list<int> order;
std::list<ant> tu;
int main() {
int l, q;
scanf("%d%d", &l, &q);
int before = 0;
int cnt = 0;
for (int i = 0; i < q; i++) {
int t, p;
scanf("%d%d", &t, &p);
for (std::list<ant>::iterator it = tu.begin(); it != tu.end(); it++) {
if (it->d == 1) {
it->x += t - before;
if (it->x > l) {
it->d = -1;
it->x = l - (it->x - l);
}
}
else {
it->x -= t - before;
if (it->x <0) {
it->d = 1;
it->x = -it->x;
}
}
}
tu.sort();
if (p == 1) {
int x, d;
scanf("%d%d", &x, &d);
int k = 0;
std::list<ant>::iterator it;
std::list<int>::iterator ord = order.begin();
for (it = tu.begin(); it != tu.end(); it++,ord++) {
if (it->x>x) {
break;
}
}
tu.insert(it, ant(x, d));
order.insert(ord, cnt + 1);
cnt++;
}
else {
int a;
scanf("%d", &a);
std::list<ant>::iterator itt = tu.begin();
for (std::list<int>::iterator it = order.begin(); it != order.end(); it++,itt++) {
if ((*it) == a) {
printf("%d\n", itt->x);
}
}
}
before = t;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |