# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
95205 | ekrem | 케이크 (CEOI14_cake) | C++98 | 2069 ms | 6392 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;
int n, m, c, q, l, r, mx, a[N], b[N], u[N], yer[N];
pair < int , int > amk;
char ch;
void yap(int l, int r, int x, int art){
if(art >= 1)
for(int i = l; i <= r; i++, x++)
a[i] = x;
else
for(int i = l; i >= r; i--, x++)
a[i] = x;
}
void duzenle(){
l = 1;
r = n;
for(int i = 1; i <= mx; i++){
if(yer[i] < l or yer[i] > r)
continue;
if(c < yer[i]){
yap(yer[i], r, yer[i] - l + 1, 1);
r = yer[i] - 1;
}
else{
yap(yer[i], l, r - yer[i] + 1, -1);
l = yer[i] + 1;
}
}
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d %d",&n ,&c);
for(int i = 1; i <= n; i++){
scanf("%d",b + i);
yer[n - b[i] + 1] = i;
}
mx = min(10, n - 1);
u[c] = 1;
for(int i = 1; i <= mx; i++){
amk = mp(0, 0);
for(int j = 1; j <= n; j++)
if(!u[j])
amk = max(amk, mp(b[j], j));
yer[i] = amk.nd;
u[amk.nd] = 1;
}
// for(int i = 1; i <= mx; i++)
// cout << yer[i] << endl;
l = c - 1;
r = c + 1;
a[c] = ++m;
while(l >= 1 and r <= n){
if(b[l] < b[r])
a[l--] = ++m;
else
a[r++] = ++m;
}
while(l >= 1)
a[l--] = ++m;
while(r <= n)
a[r++] = ++m;
// for(int i = 1; i <= n; i++)
// cout << a[i] << " ";
// cout << endl;
scanf("%d",&q);
while(q--){
scanf(" %c",&ch);
if(ch == 'F'){
int x;
scanf("%d",&x);
printf("%d\n", a[x] - 1);
continue;
}
int x, y;
scanf("%d %d",&x ,&y);
for(int i = mx; i >= y + 1; i--)
yer[i] = yer[i - 1];
yer[y] = x;
// for(int i = 1; i <= mx; i++)
// cout << yer[i] << " ";
// cout << endl;
// for(int i = 1; i <= n; i++)
// cout << a[i] << " ";
// cout << endl;
duzenle();
// for(int i = 1; i <= n; i++)
// cout << a[i] << " ";
// cout << endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |