# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
538200 |
2022-03-16T08:42:58 Z |
AdamGS |
Floppy (RMI20_floppy) |
C++17 |
|
97 ms |
12996 KB |
#include "floppy.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=4e4+7;
pair<int,int>tr[4*LIM];
string s;
int n, li;
int cnt(int l, int r) {
l+=n; r+=n;
pair<int,int>ans=max(tr[l], tr[r]);
while(l/2!=r/2) {
if(l%2==0) ans=max(ans, tr[l+1]);
if(r%2==1) ans=max(ans, tr[r-1]);
l/=2; r/=2;
}
return ans.nd;
}
void koduj(int l, int r) {
int x=cnt(l, r);
if(x!=l) {
s+="1";
koduj(l, x-1);
} else s+="0";
if(x!=r) {
s+="1";
koduj(x+1, r);
} else s+="0";
}
int odkoduj(int v, int p) {
int ile=0;
++li;
if(s[li-1]=='1') ile=odkoduj(v-1, p);
tr[n+p+ile]={v, p+ile};
++li; ++ile;
if(s[li-1]=='1') odkoduj(v-1, p+ile);
return ile;
}
void read_array(int subtask_id, const vector<int> &V) {
n=1;
while(n<V.size()) n*=2;
rep(i, V.size()) tr[n+i]={V[i], i};
for(int i=n-1; i; --i) tr[i]=max(tr[2*i], tr[2*i+1]);
s="";
koduj(0, V.size()-1);
save_to_floppy(s);
}
vector<int>solve_queries(int subtask_id, int N, const string &V,
const vector<int>&A, const vector<int>&B) {
s=V;
n=1;
while(n<N) n*=2;
odkoduj(0, 0);
for(int i=n-1; i; --i) tr[i]=max(tr[2*i], tr[2*i+1]);
vector<int>ans;
rep(i, A.size()) ans.pb(cnt(A[i], B[i]));
return ans;
}
Compilation message
floppy.cpp: In function 'void read_array(int, const std::vector<int>&)':
floppy.cpp:46:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | while(n<V.size()) n*=2;
| ~^~~~~~~~~
floppy.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
floppy.cpp:47:3: note: in expansion of macro 'rep'
47 | rep(i, V.size()) tr[n+i]={V[i], i};
| ^~~
floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
5 | #define rep(a, b) for(int a = 0; a < (b); ++a)
| ^
floppy.cpp:61:3: note: in expansion of macro 'rep'
61 | rep(i, A.size()) ans.pb(cnt(A[i], B[i]));
| ^~~
stub.cpp: In function 'void run2()':
stub.cpp:101:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
101 | if (query_answers.size() != M) {
| ~~~~~~~~~~~~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
31 ms |
3552 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
97 ms |
12996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |