Submission #15426

#TimeUsernameProblemLanguageResultExecution timeMemory
15426skeksk91통로 위의 개미 (kriii3_X)C++98
0 / 85
13 ms1588 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...