이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <set>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <fstream>
#include <complex>
#include <stack>
#include <set>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define cd complex<double>
#define ld long double
#define pld pair<ld,ld>
#define iii pair<ii,int>
#define vv vector
using namespace std;
const int MAXN = 250*1000+10;
int arr[MAXN];
int n;
inline ll getMax(int l,int r){
int mx = 0;
FORE(i,l,r)mx = max(mx,arr[i]);
return mx;
}
inline int getFirst(int a,int mx){
while(a < n){
if(arr[a] > mx)return a;
a++;
}
return a;
}
inline int getFirst2(int a,int mx){
while(a > -1){
if(arr[a] > mx)return a;
a--;
}
return a;
}
int findCnt(int a,int b){
int ptr1 = a;
int ptr2 = a;
int cnt = 0;
if(a == b)return 0;
ptr1 = a-1;
ptr2 = a+1;
cnt = 1;
while(1){
//cout << ptr1 << " " << ptr2 << endl;
if(ptr1 == b-1 or ptr2 == b+1)return cnt-1;
if(ptr2 == n)ptr1--;
else if(ptr1 == -1)ptr2++;
else if(arr[ptr2] < arr[ptr1])ptr2++;//,cout << "boo1" << endl;
else ptr1--;//,cout << "boo2" << endl;
cnt++;
}
//cout << endl;
}
set<pair<ll,int>,greater<pair<ll,int> > > st;
int main(){
int a;
cin >> n >> a;
a--;
FOR(i,n){
cin >> arr[i];
st.insert({arr[i],i});
}
int q;
cin >> q;
while(q--){
/*
FOR(i,n)cout << arr[i] << " ";cout << endl;
for(auto e : st)cout << e.ss+1 << " ";cout << endl;
cout << endl;*/
char c;
cin >> c;
if(c == 'E'){
int i,e;
cin >> i >> e;
i--;
st.erase({arr[i],i});
if(e == 1){
st.insert({(*st.begin()).ff+1,i});
arr[i] = (*st.begin()).ff;
continue;
}
vector<pair<ll,int> > v;
FOR(i,e-1){
v.pb(*st.begin());
st.erase(*st.begin());
}
//cout << "got till here" << endl;
st.insert({v.back().ff,i});
arr[i] = v.back().ff;
for(auto e: v){
st.insert({e.ff+1,e.ss});
arr[e.ss] = e.ff+1;
}
}else{
int b;
cin >> b;
b--;
//cout << b << " " << a << endl;
//cout << findCnt(a,b) << endl;
//continue;
if(b == a)cout << 0 << endl;
else if(b < a){
int mx = getMax(b,a-1);
int c = getFirst(a+1,mx);
cout << c - b - 1 << endl;
}else{
int mx = getMax(a+1,b);
int c = getFirst2(a-1,mx);
cout << b - c - 1 << endl;
}
}
}
return 0;
}
# | 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... |