This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<algorithm>
typedef long long ll;
ll re(ll x, ll y){
return (x % y + y) % y;
}
int L, Q;
int W[1002], cw, tW[1002], C[1002];
int main(){
scanf("%d%d", &L, &Q);
int i;
for (i = 1; i <= Q; i++){
ll t;
scanf("%lld", &t);
int p;
scanf("%d", &p);
if (p == 1){
int a, b;
scanf("%d%d", &a, &b);
int w = (b == 1 ? a : 2 * L - a);
ll rew = re(w - t, 2 * L);
W[++cw] = rew;
for (int j = 1; j < cw; j++){
int tmp = L - abs(L - re(W[j] + t, 2 * L));
if (L - abs(L - w) > tmp)C[cw]++;
}
for (int j = 1; j < cw; j++)if (C[j] >= C[cw])C[j]++;
}
else{
int a;
scanf("%d", &a);
int j;
for (j = 1; j <= cw; j++){
tW[j] = L - abs(L - re((W[j] + t), 2 * L));
}
std::sort(tW + 1, tW + 1 + cw);
printf("%d\n", tW[C[a]+1]);
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |