This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#define int long long
#define endl '\n'
#define mod 1000000007;
using namespace std;
int A[250001]; pair<int,int> P[250001];
int seg[1<<20];
int N,Left,Right,V;
int plc[151],s[151];
map<int,int>cc[151];
vector<int>d[151];
int vs[250001];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,a; cin >> n >> a;
for(int i = 0; i < n; i++) {
cin >> A[i];
P[i].first = A[i];
P[i].second = i + 1;
}
sort(P,P+n);
deque<int>tp;
for(int i = 1; i <= min(n,(int)10); i++) tp.push_back(P[i - 1].second);
deque<int>ee;
for(int i = 11; i <= n; i++) ee.push_back(P[i - 1].second);
int t; cin >> t;
while(t--){
char x; int c,d; cin >> x >> c;
if(x == 'E'){
cin >> d;
int plc = -1, new_val = n - d + 1;
for(int i = 0; i < min(n,(int)10); i++){
if(tp[i] == c){
plc = i;
}
}
if(new_val == plc + 1) continue;
deque<int>nw;
for(int i = 0; i < min(n,(int)10); i++){
if(i + 1 == new_val){
nw.push_back(c);
}
if(plc != -1){
if(tp[i] != c) nw.push_back(tp[i]);
}else if(i != 9 && tp[i] != c) nw.push_back(tp[i]);
}
if(plc == -1){
ee.push_front(tp[9]);
}
tp = nw;
}else{
int ct = 0;
for(int i = 0; i < min(n,(int)10); i++){
A[tp[i]] = i + 1;
vs[tp[i]] = 1;
}
deque<int>nw;
for(int i = 0; i < ee.size(); i++){
if(!vs[ee[i]]) {
A[ee[i]] = ct + 11;
nw.push_back(ee[i]);
ct++;
}
vs[ee[i]] = 1;
}
for(int i = 1; i <= n; i++) vs[i] = 0;
ee = nw;
c--;
int l = a - 2, r = a, cnt = 0;
if(a - 1 == c){
cout << 0 << endl;
continue;
}
while(1){
int mx1 = 1e18, mx2 = 1e18;
cnt++;
if(l >= 0){
mx1 = A[l];
}
if(r < n){
mx2 = A[r];
}
if(mx1 < mx2){
if(l == c) break;
l--;
}else{
if(r == c) break;
r++;
}
}
cout << cnt << endl;
}
}
return 0;
}
Compilation message (stderr)
cake.cpp: In function 'int main()':
cake.cpp:148:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
148 | for(int i = 0; i < ee.size(); i++){
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |