Submission #276995

#TimeUsernameProblemLanguageResultExecution timeMemory
276995super_j6Cake (CEOI14_cake)C++14
35 / 100
2088 ms2960 KiB
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 250002;
int n, k, q;
int a[mxn], b[mxn];

void sol(){
	b[k] = 0;
	for(int i = 1, l = k - 1, r = k + 1; i < n; i++){
		if(a[l] < a[r]) b[l--] = i;
		else b[r++] = i;
	}
}

void pr(){
	for(int i = 1; i <= n; i++) cout << a[i] << " ";
	cout << endl;
	for(int i = 1; i <= n; i++) cout << b[i] << " ";
	cout << endl;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		a[i]--;
	} 
	a[0] = a[n + 1] = n;
	
	sol();
	//pr();
	
	cin >> q;
	
	while(q--){
		char t;
		cin >> t;
		if(t == 'F'){
			int x;
			cin >> x;
			cout << b[x] << endl;
		}else{
			int x, y;
			cin >> x >> y;
			y = n - y;
			for(int i = 1; i <= n; i++){
				if(i != x && a[i] >= min(a[x], y) && a[i] <= max(a[x], y)){
					a[i] += 2 * (a[x] > y) - 1;
				}
			}
			a[x] = y;
			//pr();
			sol();
		}
	}

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...