# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
761233 | ksu2009en | Floppy (RMI20_floppy) | C++17 | 80 ms | 5728 KiB |
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 <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <cstring>
#include <unordered_map>
using namespace std;
typedef long long ll;
#include "floppy.h"
string convert(ll n){
string ans;
ll mx = 0;
for(int i = 17; i >= 0; i--)
if((n >> i) % 2 != 0){
mx = i;
break;
}
for(int i = 0; i <= mx; i++){
if((n >> i) % 2 != 0)
ans += "1";
else
ans += "0";
}
reverse(ans.begin(), ans.end());
return ans;
}
ll get(string a){
ll ans = 0;
ll p = 1;
for(int i = a.size() - 1; i >= 0; i--){
ans += (a[i] - '0') * p;
p *= 2;
}
return ans;
}
string fill0(string a, ll n){
reverse(a.begin(), a.end());
ll c = n - a.size();
for(int i = 0; i < c; i++)
a += "0";
reverse(a.begin(), a.end());
return a;
}
void squize(vector<ll> &a){
vector<ll> b = a;
sort(b.begin(), b.end());
map<ll, ll> mp;
ll step = 0;
for(auto i: b)
if(!mp.count(i))
mp[i] = step++;
for(auto &i: a)
i = mp[i];
}
void read_array(int subtask_id, const std::vector<int> &v) {
vector<string>d;
vector<ll>a;
for(auto i: v)
a.push_back(i);
squize(a);
for(auto i: a){
d.push_back(convert(i));
}
for(auto &i: d)
i = fill0(i, 14);
string ans;
for(auto i: d)
ans += i;
save_to_floppy(ans);
}
std::vector<int> solve_queries(int subtask_id, int N,
const std::string &bits,
const std::vector<int> &a, const std::vector<int> &b) {
vector<ll> d;
for(int i = 0; i < bits.size(); i += 14){
string c;
for(int j = i; j < i + 14; j++)
c += bits[j];
d.push_back(get(c));
}
vector<int>ans;
for(int i = 0; i < a.size(); i++){
ll mx = -1, pos = 0;
for(int j = a[i]; j <= b[i]; j++){
if(d[j] > mx){
mx = d[j];
pos = j;
}
}
ans.push_back(pos);
}
return ans;
}
/*
2
4 1
-2 -4 2 0
0 1 0
*/
Compilation message (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... |