Submission #15482

# Submission time Handle Problem Language Result Execution time Memory
15482 2015-07-12T08:19:12 Z myungwoo 통로 위의 개미 (kriii3_X) C++14
30 / 85
3000 ms 7976 KB
#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
1 Correct 26 ms 7976 KB Output is correct
2 Correct 24 ms 7976 KB Output is correct
3 Correct 24 ms 7976 KB Output is correct
4 Correct 27 ms 7976 KB Output is correct
5 Correct 26 ms 7976 KB Output is correct
6 Correct 27 ms 7976 KB Output is correct
7 Correct 26 ms 7976 KB Output is correct
8 Correct 25 ms 7976 KB Output is correct
9 Correct 26 ms 7976 KB Output is correct
10 Correct 27 ms 7976 KB Output is correct
11 Correct 14 ms 7976 KB Output is correct
12 Correct 21 ms 7976 KB Output is correct
13 Correct 10 ms 7976 KB Output is correct
14 Correct 12 ms 7976 KB Output is correct
15 Correct 15 ms 7976 KB Output is correct
16 Correct 34 ms 7976 KB Output is correct
17 Correct 34 ms 7976 KB Output is correct
18 Correct 26 ms 7976 KB Output is correct
19 Correct 14 ms 7976 KB Output is correct
20 Correct 25 ms 7976 KB Output is correct
21 Correct 10 ms 7976 KB Output is correct
22 Correct 12 ms 7976 KB Output is correct
23 Correct 26 ms 7976 KB Output is correct
24 Correct 30 ms 7976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3000 ms 7976 KB Program timed out
2 Halted 0 ms 0 KB -