Submission #502191

# Submission time Handle Problem Language Result Execution time Memory
502191 2022-01-05T12:46:36 Z keta_tsimakuridze Floppy (RMI20_floppy) C++14
0 / 100
35 ms 3424 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, f[maxn];
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 + 1003, 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 - 1) return;
	int x = 0;
	for(int i = cur; i < cur + 14; i++) {
		x += (s[i] == '1') * (1 << (i - cur));
	}
	cur += 14; f[x] = 1;
	upd(1, x, 0, n, cur / 14 - 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); 
        for(int i = 0; i < n; i++) if(!f[i]) upd(1, i, 0, n, n + 5);
        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 - 1) 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 < 14; 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:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         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 2 ms 788 KB Output is correct
2 Incorrect 2 ms 756 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 3424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 3420 KB L is too large
2 Halted 0 ms 0 KB -