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 <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("%d%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... |