#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using str = string;
#define all(a) a.begin(), a.end()
#define print(a) for (auto elem:a) cout<<elem<<' '; cout<<'\n'
#define segprep(b) resize(1<<((int)ceil(log2(b.size()))+1))
#define FOR(a) for (int _ = 0; _ < a; _++)
vi paint(int n) {
vi labels(n+1, 0);
labels.back() = 69;
int maxx = 1;
while(maxx*(maxx+1)/2 <= n) maxx++;
maxx--;
fill(labels.begin()+maxx*(maxx+1)/2, labels.end()-1, 1);
for (int sect = 1; sect <= maxx; sect++){
labels.at(sect*(sect+1)/2-1) = 1;
}
return labels;
}
int find_location(int n, vi c) {
int k = 69;
if (find(all(c), -1) != c.end()){
return n-(find(all(c), -1)-c.begin());
}
int maxx = 1;
while(maxx*(maxx+1)/2 <= n) maxx++;
maxx--;
if (c.back() == c.at(k-2) && c.back() == 1){
// mamy filler koncowy
int filler_start = maxx*(maxx+1)/2;
int fill_cnt = (find(c.rbegin(), c.rend(), 0)-c.rbegin())-1;
int end_ind = filler_start+fill_cnt-1;
return end_ind-k+1;
}
vi ones_inds;
for (int i = 0; (i < k) && ((int)ones_inds.size() < 2); i++){
if (c.at(i) == 1) ones_inds.push_back(i);
}
int section = ones_inds.back()-ones_inds.front();
int second_one_ind = section*(section+1)/2-1;
return second_one_ind-ones_inds.back();
}
/*
static int max_k = 0;
static int r, n, k, q, x;
static std::vector<int> labels, c, answers;
int main() {
assert(scanf("%d", &r) == 1);
for (int tc = 0; tc < r; tc++) {
assert(scanf("%d%d", &n, &q) == 2);
labels = paint(n);
if ((int)labels.size() != n + 1) {
printf("Number of labels not equal to %d\n", n + 1);
exit(0);
}
for (int i = 0; i < n; i++) {
if (labels[i] != 0 && labels[i] != 1) {
printf("Label not 0 or 1\n");
exit(0);
}
}
k = labels[n];
if (k < 0 || k > 1000) {
printf("Label not in range 0 to 1000\n");
exit(0);
}
if (k > max_k) {
max_k = k;
}
for (int i = 0; i < q; i++) {
assert(scanf("%d", &x) == 1);
c.clear();
for (int j = x; j < x + k; j++) {
if (j >= n) {
c.push_back(-1);
} else {
c.push_back(labels[j]);
}
}
answers.push_back(find_location(n, c));
}
}
printf("%d\n", max_k);
for (int ans : answers) {
printf("%d\n", ans);
}
exit(0);
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |