Submission #15559

#TimeUsernameProblemLanguageResultExecution timeMemory
15559cki86201통로 위의 개미 (kriii3_X)C++98
30 / 85
180 ms1096 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...