Submission #84022

#TimeUsernameProblemLanguageResultExecution timeMemory
84022SaboonCake (CEOI14_cake)C++17
35 / 100
2078 ms3572 KiB
#include <bits/stdc++.h>
#define MP make_pair
#define F first
#define PB push_back
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 3e5 + 4;

int a[maxn], pos[maxn];

int main (){
	ios_base::sync_with_stdio(false);
	int n, st;
	scanf ("%d%d", &n, &st);
	for (int i = 1; i <= n; i++) {
		scanf ("%d", &a[i]);
		a[i] = n - a[i] + 1;
	}

	int ptr1 = st - 1, ptr2 = st + 1, tmp = 1;
	while (ptr1 >= 1 or ptr2 <= n) {
		if (ptr1 < 1) {
			pos[ptr2 ++] = tmp ++;
		}
		else if (ptr2 > n) {
			pos[ptr1 --] = tmp ++;
		}
		else {
			if (a[ptr1] > a[ptr2]) {
				pos[ptr1 --] = tmp ++;
			}
			else {
				pos[ptr2 ++] = tmp ++;
			}
		}
	}

	int m;
	scanf ("%d", &m);
	for (int i = 0; i < m; i++) {
		char type;
		scanf (" %c", &type);
		if (type == 'F') {
			int idx;
			scanf ("%d", &idx);
			printf ("%d\n", pos[idx]);
		}
		else {
			int idx, x;
			scanf ("%d%d", &idx, &x);
			for (int j = 1; j <= n; j++) {
				if (a[j] >= x and a[j] < a[idx]) {
					a[j] ++;
				}
			}
			a[idx] = x;

			int ptr1 = st - 1, ptr2 = st + 1, tmp = 1;
			while (ptr1 >= 1 or ptr2 <= n) {
				if (ptr1 < 1) {
					pos[ptr2 ++] = tmp ++;
				}
				else if (ptr2 > n) {
					pos[ptr1 --] = tmp ++;
				}
				else {
					if (a[ptr1] > a[ptr2]) {
						pos[ptr1 --] = tmp ++;
					}
					else {
						pos[ptr2 ++] = tmp ++;
					}
				}
			}
		}
	}
}

Compilation message (stderr)

cake.cpp: In function 'int main()':
cake.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d%d", &n, &st);
  ~~~~~~^~~~~~~~~~~~~~~~~
cake.cpp:19:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%d", &a[i]);
   ~~~~~~^~~~~~~~~~~~~
cake.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d", &m);
  ~~~~~~^~~~~~~~~~
cake.cpp:45:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf (" %c", &type);
   ~~~~~~^~~~~~~~~~~~~~
cake.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf ("%d", &idx);
    ~~~~~~^~~~~~~~~~~~
cake.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf ("%d%d", &idx, &x);
    ~~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...