Submission #676566

#TimeUsernameProblemLanguageResultExecution timeMemory
676566vjudge1Cake (CEOI14_cake)C++17
35 / 100
2091 ms2892 KiB
#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 1000000007
#define INF 10000000
#define ll long long
//#define cin fin
//#define cout fout
#define fi first
#define se second
using namespace std;
///ofstream fout("addictive.out");
///ifstream fin("addictive.in");

int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    int n, a; cin >> n >> a; int arr[n], ans[n] = {};
    for(int i = 0; i < n; i++) {
        int x; cin >> x;
        arr[i] = n-x+1;
    }
    int cnt = 1;
    int l = a-2, r = a;
    while(l >= 0 || r < n) {
        if(r >= n) {
            ans[l] = cnt;
            cnt++;
            l--;
        }
        else if(l < 0) {
            ans[r] = cnt;
            cnt++;
            r++;
        }
        else if(arr[l] > arr[r]) {
            ans[l] = cnt;
            cnt++;
            l--;
        }
        else {
            ans[r] = cnt;
            cnt++;
            r++;
        }
    }


    int q; cin >> q;
    while(q--) {
        char c; cin >> c;
        if(c == 'E') {
            int x, y; cin >> x >> y; x--;
            for(int i = 0; i < n; i++) {
                if(arr[i] < arr[x] && arr[i] >= y) {arr[i]++;}
            }
            arr[x] = y; cnt = 1; l = a-2; r = a;
            while(l >= 0 || r < n)
            {
                if(r >= n)
                {
                    ans[l] = cnt;
                    cnt++;
                    l--;
                }
                else if(l < 0)
                {
                    ans[r] = cnt;
                    cnt++;
                    r++;
                }
                else if(arr[l] > arr[r])
                {
                    ans[l] = cnt;
                    cnt++;
                    l--;
                }
                else
                {
                    ans[r] = cnt;
                    cnt++;
                    r++;
                }
            }
        }
        else {
            int x; cin >> x; cout << ans[x-1] << endl;
        }
    }
    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...