This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 3e5 + 5;
struct SegTree {
};
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, s, q;
cin >> n >> s;
vector<ll> v(n+1), v2;
for(int i=1; i<=n; i++) cin >> v[i], v[i] *= (ll)1e6;
for(int i=1; i<=n; i++) v2.push_back(i);
sort(v2.begin(), v2.end(), [&](int a, int b) {
return v[a] > v[b];
});
while(v2.size() > 10) v2.pop_back();
cin >> q;
while(q--) {
char t;
cin >> t;
if(t == 'F') {
int p;
cin >> p;
if(p == s) {
cout << 0 << '\n';
continue;
}
int l=s, r=s, ans=0;
while(l != p && r != p) {
ans++;
if(l - 1 == 0) r++;
else if(r + 1 > n) l--;
else if(v[l-1] < v[r+1]) l--;
else r++;
}
cout << ans << '\n';
} else {
int a, b;
cin >> a >> b;
v[a] = v[v2[b-1]] + 1;
//check if its almost in top 10
bool ok = 0;
for(int i=0; i<v2.size()&&!ok; i++)
if(v2[i] == a) ok = 1;
if(!ok) v2.push_back(a);
sort(v2.begin(), v2.end(), [&](int a, int b) {
return v[a] > v[b];
});
if(!ok) v2.pop_back();
}
}
return 0;
}
Compilation message (stderr)
cake.cpp: In function 'int main()':
cake.cpp:65:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0; i<v2.size()&&!ok; 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... |