답안 #110545

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110545 2019-05-11T06:49:31 Z ckodser 케이크 (CEOI14_cake) C++14
46.6667 / 100
2000 ms 15484 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 250005, MXS = 1 << 18;
int n, q, st, A[N], MX[MXS * 2];
struct CMP {
	inline bool operator () (int i, int j) {
		return (A[i] < A[j]);
	}
};
set < int , CMP > S;
inline set < int > :: iterator GetEnd()
{
	auto it = S.end(); it --;
	return it;
}
inline void Set(int i, int val)
{
	for (i += MXS; i; i >>= 1)
		MX[i] = max(MX[i], val);
}
inline int Get(int le, int ri)
{
	int Mx = 0;
  	for (int i = le; i < ri; i++)
      	Mx = max(Mx, A[i]);
  	return (Mx);
  
	/*for (le += MXS, ri += MXS; le < ri; le >>= 1, ri >>= 1)
	{
		if (le & 1) Mx = max(Mx, MX[le]), le ++;
		if (ri & 1) ri --, Mx = max(Mx, MX[ri]);
	}
	return (Mx);*/
}
int GetR(int le, int val, int id = 1, int l = 0, int r = MXS)
{
	/*if (r <= le || MX[id] <= val)
		return n;
	if (r - l < 2)
		return l;
	int res = GetR(le, val, id << 1, l, (l + r) >> 1);
	if (res < n) return (res);
	return (GetR(le, val, id << 1 | 1, (l + r) >> 1, r));*/

	for (int i = le; i < n; i++)
		if (A[i] > val)
			return i;
	return n;
}
int GetL(int ri, int val, int id = 1, int l = 0, int r = MXS)
{
	/*if (ri <= l || MX[id] <= val)
		return -1;
	if (r - l < 2)
		return l;
	int res = GetL(ri, val, id << 1 | 1, (l + r) >> 1, r);
	if (res > -1) return (res);
	return (GetL(ri, val, id << 1, l, (l + r) >> 1));*/

	for (int i = ri - 1; i >= 0; i --)
		if (A[i] > val)
			return i;
	return -1;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> st; st --;
	for (int i = 0; i < n; i++)
	{
		cin >> A[i];
		S.insert(i);
		Set(i, A[i]);
	}
	cin >> q;
	for (; q; q --)
	{
		char ch;
		int id, k;
		cin >> ch >> id;
		id --;
		if (ch == 'E')
		{
			cin >> k;
			vector < int > vec;
			for (int i = 0; i < k - 1; i++)
				vec.push_back(*GetEnd()), S.erase(GetEnd());
			int a = A[*GetEnd()] + 1;
			S.erase(id);
			A[id] = a;
			S.insert(S.end(), id);
			Set(id, A[id]);
			for (int i = k - 2; ~ i; i --)
			{
				A[vec[i]] = ++ a;
				S.insert(S.end(), vec[i]);
				Set(vec[i], A[vec[i]]);
			}
			continue;
		}

		if (id == st)
			printf("0\n");
		else if (id < st)
			printf("%d\n", GetR(st + 1, Get(id, st)) - id - 1);
		else
			printf("%d\n", id - GetL(st, Get(st + 1, id + 1)) - 1);
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 14 ms 512 KB Output is correct
5 Correct 38 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 350 ms 980 KB Output is correct
2 Correct 229 ms 1040 KB Output is correct
3 Correct 260 ms 1024 KB Output is correct
4 Correct 172 ms 1024 KB Output is correct
5 Correct 468 ms 1892 KB Output is correct
6 Correct 412 ms 1920 KB Output is correct
7 Correct 342 ms 2040 KB Output is correct
8 Correct 201 ms 2040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2045 ms 6704 KB Time limit exceeded
2 Execution timed out 2052 ms 6668 KB Time limit exceeded
3 Execution timed out 2041 ms 6980 KB Time limit exceeded
4 Correct 2 ms 384 KB Output is correct
5 Execution timed out 2100 ms 15396 KB Time limit exceeded
6 Execution timed out 2070 ms 15304 KB Time limit exceeded
7 Execution timed out 2061 ms 15484 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 640 KB Output is correct
2 Correct 118 ms 864 KB Output is correct
3 Correct 908 ms 3840 KB Output is correct
4 Correct 777 ms 3736 KB Output is correct
5 Correct 146 ms 888 KB Output is correct
6 Execution timed out 2058 ms 4864 KB Time limit exceeded
7 Correct 548 ms 1656 KB Output is correct
8 Correct 359 ms 6316 KB Output is correct
9 Execution timed out 2057 ms 15224 KB Time limit exceeded
10 Correct 560 ms 1652 KB Output is correct
11 Execution timed out 2066 ms 2808 KB Time limit exceeded
12 Execution timed out 2064 ms 12516 KB Time limit exceeded
13 Execution timed out 2060 ms 15452 KB Time limit exceeded