# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
229962 |
2020-05-07T11:17:39 Z |
Ruxandra985 |
Cake (CEOI14_cake) |
C++14 |
|
590 ms |
12280 KB |
#include <bits/stdc++.h>
#define DIMN 250010
#define ADD 1
using namespace std;
long long v[DIMN] , f[20] , aux[DIMN];
pair <long long , int> aint[4 * DIMN] , p[DIMN] , w[20];
int n;
void build (int nod , int st , int dr){
int mid = (st + dr)/2;
if (st == dr){
aint[nod] = make_pair( v[st] , st );
return;
}
build (2 * nod , st , mid);
build (2 * nod + 1 , mid + 1 , dr);
aint[nod] = max(aint[2 * nod] , aint[2 * nod + 1]);
}
void update (int nod , int st , int dr , int poz , long long val){
int mid = (st + dr)/2;
if (st == dr){
aint[nod] = make_pair( val , st );
return;
}
if (poz <= mid)
update (2 * nod , st , mid , poz , val);
else update (2 * nod + 1 , mid + 1 , dr , poz , val);
aint[nod] = max(aint[2 * nod] , aint[2 * nod + 1]);
}
long long query_fixed (int nod , int st , int dr , int l , int r){
int mid = (st + dr)/2;
long long sol = 0;
if (l <= st && dr <= r){
return aint[nod].first;
}
if (l <= mid)
sol = max(sol , query_fixed (2 * nod , st , mid , l , r));
if (mid + 1 <= r)
sol = max(sol , query_fixed (2 * nod + 1 , mid + 1 , dr , l , r));
return sol;
}
int query_check (int nod , int st , int dr , long long val , int l , int r , int type){
int mid = (st + dr)/2;
int sol;
if (type == -1)
sol = n + 1;
else sol = 0;
if (l <= st && dr <= r){
/// vreau fie cel mai mare din interval cu valoarea > val
/// fie cel mai mic din interval cu aceeasi proprietate
if (st == dr){
if (aint[nod].first > val){
return st; /// pozitie valida
}
else {
/// nu e pozitie valida :(
if (type == -1)
return n + 1;
else return 0;
}
}
if (type == -1){ /// il vreau pe cel mai mic
if (aint[2 * nod].first > val)
return query_check(2 * nod , st , mid , val , l , r , type);
else if (aint[2 * nod + 1].first > val)
return query_check (2 * nod + 1 , mid + 1 , dr , val , l , r , type);
else return n + 1; /// nu exista
}
else { /// il vreau pe cel mai mare
if (aint[2 * nod + 1].first > val)
return query_check(2 * nod + 1 , mid + 1 , dr , val , l , r , type);
else if (aint[2 * nod].first > val)
return query_check (2 * nod , st , mid , val , l , r , type);
else return 0; /// nu exista
}
}
if (l <= mid){
if (type == -1)
sol = min(sol , query_check (2 * nod , st , mid , val , l , r , type));
else sol = max(sol , query_check (2 * nod , st , mid , val , l , r , type));
}
if (mid + 1 <= r){
if (type == -1)
sol = min(sol , query_check (2 * nod + 1 , mid + 1 , dr , val , l , r , type));
else sol = max(sol , query_check (2 * nod + 1 , mid + 1 , dr , val , l , r , type));
}
return sol;
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int a , q , i , sol , idx , poz , j , x , elem = 0 , ok;
long long val;
char c;
fscanf (fin,"%d%d",&n,&a);
for (i = 1 ; i <= n ; i++){
fscanf (fin,"%lld",&v[i]);
if (v[i] > n - 10)
w[++elem] = make_pair(v[i] , i);
}
sort (w + 1 , w + elem + 1);
w[elem + 1] = make_pair(n + 1 , 0);
build (1 , 1 , n);
fscanf (fin,"%d\n",&q);
for (;q;q--){
c = fgetc(fin);
if (c == 'E'){
fscanf (fin,"%d%d\n",&idx,&poz);
ok = 1;
for (i = 1 ; i <= elem ; i++){
if (w[i].second == idx)
ok = i;
}
if (ok == elem - poz + 1)
continue;
j = elem - poz + 1; /// aia care trb inlocuita
val = w[j + 1].first;
update (1 , 1 , n , idx , val);
for (i = j + 1 ; i <= elem ; i++){
w[i].first++;
update (1 , 1 , n , w[i].second , w[i].first);
}
w[elem + 1].first++;
for (i = ok ; i < j ; i++)
w[i] = w[i + 1];
w[j] = make_pair(val , idx);
/// val e noua valoare
aux[poz] = val;
}
else { /// query urile
fscanf (fin,"%d\n",&x);
if (a < x){
val = query_fixed (1 , 1 , n , a + 1 , x);
sol = x - a + 1 + a - query_check (1 , 1 , n , val , 1 , a - 1 , 1) - 1;
}
else if (a == x)
sol = 1;
else {
val = query_fixed (1 , 1 , n , x , a - 1);
sol = a - x + 1 + query_check (1 , 1 , n , val , a + 1 , n , -1) - a - 1;
}
fprintf (fout,"%d\n", sol - 1);
}
}
return 0;
}
Compilation message
cake.cpp: In function 'int main()':
cake.cpp:133:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%d%d",&n,&a);
~~~~~~~^~~~~~~~~~~~~~~~~~
cake.cpp:136:16: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%lld",&v[i]);
~~~~~~~^~~~~~~~~~~~~~~~~~
cake.cpp:148:12: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%d\n",&q);
~~~~~~~^~~~~~~~~~~~~~~
cake.cpp:155:20: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%d%d\n",&idx,&poz);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
cake.cpp:190:20: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
fscanf (fin,"%d\n",&x);
~~~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
279 ms |
1016 KB |
Output is correct |
2 |
Correct |
190 ms |
896 KB |
Output is correct |
3 |
Correct |
210 ms |
1016 KB |
Output is correct |
4 |
Correct |
160 ms |
1016 KB |
Output is correct |
5 |
Incorrect |
316 ms |
1656 KB |
Output isn't correct |
6 |
Correct |
266 ms |
1536 KB |
Output is correct |
7 |
Correct |
241 ms |
1536 KB |
Output is correct |
8 |
Correct |
161 ms |
1656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
110 ms |
5752 KB |
Output isn't correct |
2 |
Correct |
85 ms |
5692 KB |
Output is correct |
3 |
Correct |
73 ms |
5624 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
130 ms |
11128 KB |
Output is correct |
6 |
Incorrect |
131 ms |
11128 KB |
Output isn't correct |
7 |
Correct |
111 ms |
11000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
632 KB |
Output isn't correct |
2 |
Correct |
36 ms |
888 KB |
Output is correct |
3 |
Correct |
81 ms |
3064 KB |
Output is correct |
4 |
Incorrect |
82 ms |
3064 KB |
Output isn't correct |
5 |
Incorrect |
110 ms |
764 KB |
Output isn't correct |
6 |
Correct |
127 ms |
3320 KB |
Output is correct |
7 |
Correct |
128 ms |
1400 KB |
Output is correct |
8 |
Correct |
131 ms |
5248 KB |
Output is correct |
9 |
Incorrect |
590 ms |
12280 KB |
Output isn't correct |
10 |
Incorrect |
346 ms |
1528 KB |
Output isn't correct |
11 |
Incorrect |
428 ms |
3064 KB |
Output isn't correct |
12 |
Incorrect |
563 ms |
11768 KB |
Output isn't correct |
13 |
Incorrect |
481 ms |
12152 KB |
Output isn't correct |