Submission #121738

#TimeUsernameProblemLanguageResultExecution timeMemory
121738rajarshi_basuCake (CEOI14_cake)C++14
0 / 100
2067 ms19404 KiB
#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; } 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--){ 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; if(b == a)cout << 0 << endl; else if(b < a){ int mx = getMax(b,a); int c = getFirst(a+1,mx); cout << c - b - 1 << endl; }else{ int mx = getMax(a,b); int c = getFirst2(a-1,mx); cout << b - c- 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...