Submission #502163

# Submission time Handle Problem Language Result Execution time Memory
502163 2022-01-05T11:34:06 Z keta_tsimakuridze Floppy (RMI20_floppy) C++14
18.4517 / 100
53 ms 4780 KB
#include<bits/stdc++.h>
#include "floppy.h"
#define pii pair<int,int>
#define f first
#define s second
using namespace std;
const int maxn = 1e5 + 5;
pii tree[4 * maxn], t[4 * maxn];
vector<int> A;
int n, cur = 0, cnt = 0;
string bits, s;
void upd(int u,int ind,int l,int r,int val) {
	if(l > ind || r < ind) return;
	if(l == r) {
		t[u] = {val, l};
		return;
	}
	int mid = (l + r) / 2;
	upd(2 * u, ind, l, mid, val); upd(2 * u + 1, ind, mid + 1, r, val);
	t[u] = min(t[2 * u], t[2 * u + 1]);
}
pii Get(int u,int st,int en,int l,int r) {
	if(l > en || r < st) return {n + 1, 0};
	if(st <= l && r <= en) {
	return t[u]; }
	int mid = (l + r) / 2;
	return min(Get(2 * u, st, en, l, mid), Get(2 * u + 1, st, en, mid + 1, r));
}
void go(int l,int r) {
	if(l > r) return;
	int x = 0;
	for(int i = cur; i < cur + 16; i++) {
		x += (s[i] == '1') * (1 << (i - cur));
	}
	cur += 16;
	upd(1, x, 0, n, cur / 16 - 1);
	go(l, x - 1); go(x + 1, r); 
}
std::vector<int> solve_queries(int subtask_id, int N,
        const std::string &bits,
        const std::vector<int> &a, const std::vector<int> &b) {
        s = bits; n = N - 1;
        cur = 0;
        go(0, n); 
        vector<int> ans(a.size());
     
        for(int i = 0; i < a.size(); i++) { 
        	ans[i] = Get(1, a[i], b[i], 0, n).s;
		} 
		return ans;
}
void build(int u,int l,int r) {
	if(l == r) {
		tree[u] = {A[l], l};
		return;
	}
	int mid = (l + r) / 2;
	build(2 * u, l, mid); build(2 * u + 1, mid + 1, r);
	tree[u] = max(tree[2 * u], tree[2 * u + 1]);
}
pii get(int u, int st,int en,int l,int r) {
	if(l > en || r < st) return {-2e9, 0};
	if(st <= l && r <= en) return tree[u];
	int mid = (l + r) / 2;
	return max(get(2 * u, st, en, l, mid), get(2 * u + 1, st, en, mid + 1, r));
}
void solve(int l,int r) {
	if(l > r) return; 
	int x = get(1, l, r, 0, n).s;
	cnt++;
	assert(x >= l && x <= r);
///	assert(cnt <= n + 1);
	for(int i = 0; i < 16; i++) {
		if((1 << i) & x) bits += '1'; 
		else bits += '0';
	}
	solve(l,  x - 1); solve(x + 1, r);
}
void read_array(int subtask_id, const std::vector<int> &v) {
    bits = "";
    n = v.size(); n--;
    A = v;
    cnt  = 0;
    build(1, 0, n);
    solve(0, n); 
    save_to_floppy(bits);
}

Compilation message

floppy.cpp: In function 'std::vector<int> solve_queries(int, int, const string&, const std::vector<int>&, const std::vector<int>&)':
floppy.cpp:47:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for(int i = 0; i < a.size(); 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 Correct 3 ms 788 KB Output is correct
2 Correct 4 ms 776 KB Output is correct
3 Correct 4 ms 856 KB Output is correct
4 Correct 2 ms 788 KB Output is correct
5 Correct 4 ms 776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 43 ms 3836 KB Partially correct
2 Partially correct 36 ms 4584 KB Partially correct
3 Partially correct 35 ms 4616 KB Partially correct
4 Partially correct 36 ms 4780 KB Partially correct
5 Partially correct 39 ms 4576 KB Partially correct
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 3868 KB L is too large
2 Halted 0 ms 0 KB -