이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define MAXM 200005
#define pb push_back
typedef long long lld;
int L, M, N;
lld pos[MAXM];
struct Z{
lld t;
int p, x, d;
} Q[MAXM];
int main()
{
scanf("%d%d", &L, &M);
for (int i=1;i<=M;i++){
scanf("%lld%d%d", &Q[i].t, &Q[i].p, &Q[i].x);
if (Q[i].p == 1) scanf("%d", &Q[i].d);
}
sort(Q+1, Q+M+1, [](const Z &a, const Z &b){
return a.t < b.t;
});
vector <int> ord(1, 0);
for (int qq=1;qq<=M;qq++){
Z &q = Q[qq];
vector <lld> arr(N+1, 0);
for (int i=1;i<=N;i++){
arr[i] = (pos[i] + q.t) % (L+L);
if (arr[i] > L) arr[i] = L - (arr[i] - L);
}
sort(arr.begin()+1, arr.end());
if (q.p == 1){
if (q.d == 1){
pos[++N] = q.x - q.t;
}else{
pos[++N] = L+L - q.x - q.t;
}
int t = 0;
for (int i=1;i<N;i++) if (arr[i] < q.x) t = i;
ord.pb(0);
for (int i=N-1;i>t;i--) ord[i+1] = ord[i];
ord[t+1] = N;
}else{
for (int i=1;i<=N;i++) if (ord[i] == q.x) printf("%lld\n", arr[i]);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |