This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<queue>
#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::deque<ant> deq;
std::deque<int> order;
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::deque<ant>::iterator it = deq.begin(); it != deq.end(); it++) {
if (it->d == 1) {
it->x += t - before;
if (it->x >= l) {
it->x = l - (it->x - l);
it->d = -1;
}
}
else {
it->x -= t - before;
if (it->x <= 0) {
it->x = -it->x;
it->d = 1;
}
}
}
std::sort(deq.begin(), deq.end());
if (p == 1) {
int x, d;
scanf("%d%d", &x, &d);
int a=std::lower_bound(deq.begin(), deq.end(), ant(x, d))-deq.begin();
deq.insert(deq.begin() + a, ant(x, d));
order.insert(order.begin(), cnt + 1);
cnt++;
}
if (p == 2) {
int a;
scanf("%d", &a);
int k = 0;
for (std::deque<int>::iterator it = order.begin(); it != order.end(); it++,k++) {
if (*it == a) {
printf("%d\n", deq[k]);
break;
}
}
}
before = t;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |