output stringlengths 52 181k | instruction stringlengths 296 182k |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int arr[(int)1e5 + 1];
int q[(int)1e5 + 1];
int sol[(int)1e5 + 1];
int main() {
int n, m;
cin >> n;
cin >> arr[0];
for (int i = 1; i < n; i++) {
int x;
cin >> x;
arr[i] = arr[i - 1] + x;
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> q[i];
... | ### Prompt
Construct a CPP code solution to the problem outlined:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labele... |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int q[n], m, sum = 0;
q[0] = 0;
for (long long int i = 1; i <= n; i++) {
cin >> m;
q[i] = q[i - 1] + m;
sum += m;
}
long long int arr[sum + 1], index = 1;
for (long long int i = 1; i <= sum; i++) ... | ### Prompt
Please provide a cpp coded solution to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
long n, m, temp, p, q;
int main() {
cin >> n;
long a[n];
for (int i = 0; i < n; i++) {
cin >> p;
temp += p;
a[i] = temp;
}
cin >> m;
long b[m];
for (int i = 0; i < m; i++) {
cin >> p;
q = lower_bound(a, a + n, p) - a;
b[i] = q + 1;
}
... | ### Prompt
Please formulate a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int num[100007];
int main() {
vector<pair<int, int> > data;
int curr = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> num[i];
data.push_back(make_pair(curr + 1, curr + num[i]));
curr = curr + num[i];
}
int m;
cin >> m;
int x;
for (i... | ### Prompt
Construct a CPP code solution to the problem outlined:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labele... |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int main() {
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int n;
cin >> n;
int inp, prev = 1;
int *table = (int *)malloc(sizeof(int) * 1000001);
for (long long i = 0; i < n; i++) {
cin >> inp;
for (int j = ... | ### Prompt
Create a solution in CPP for the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled w... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
long long location = 1;
long long a_aux;
int array[n][2];
for (int i = 0; i < n; i++) {
scanf("%d", &a_aux);
array[i][0] = location;
array[i][1] = a_aux + location - 1;
location += a_aux;
}
int m, start, e... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
int arr[1100000];
using namespace std;
int main() {
memset(arr, 0, sizeof arr);
int n;
cin >> n;
int x = 1, pre = 1;
for (int i = 1; i <= n; i++) {
int c;
cin >> c;
arr[x] = i;
x += c;
}
x = arr[1];
for (int i = 1; i <= 1000000; i++) {
if (!arr[i])
arr[... | ### Prompt
Develop a solution in CPP to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int dp[1000000];
int main() {
int n;
cin >> n;
int arr[n];
int sum = 0;
int count = 1;
int k;
for (int i = 0; i < n; i++) cin >> k, sum += k, dp[i + 1] = sum;
int q;
cin >> q;
while (q--) {
int left = 0, right = n;
int a;
cin >> a;
while ... | ### Prompt
In Cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> arr(n);
cin >> arr[0];
for (int i = 1; i < n; ++i) {
cin >> arr[i];
arr[i] += arr[i - 1];
}
sort(arr.begin(), arr.end());
int m;
cin >> m;
for (int i = 0; i < m; ++i) {
int a;
cin >> a;
cout <... | ### Prompt
Develop a solution in CPP to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
long long int a[1000001];
int main() {
long long int n;
cin >> n;
int _count = 1;
for (int i = 0; i < n; i++) {
long long int x;
cin >> x;
for (int j = 0; j < x; j++) {
a[_count++] = i;
}
}
long long int x;
cin >> x;
while (x--) {
l... | ### Prompt
Please create a solution in CPP to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
while (TESTS--) {
int n;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++) cin >> a[i];
int m;
cin >> m;
vector<long long i... | ### Prompt
In Cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int> > quest(100006, vector<int>(2));
int n, i, a[100006], m, num, ans[100006], j = 0, sum = 0;
cin >> n;
for (i = 0; i < n; ++i) cin >> a[i];
cin >> m;
for (i = 0; i < m; ++i) {
cin >> num;
quest[i][0] = num;
quest[i][1] =... | ### Prompt
Develop a solution in cpp to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100050], m, q, in = 0;
map<int, int> b;
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 1; i < n; ++i) a[i] += a[i - 1];
for (int i = 0; i < a[n - 1] + 1; ++i) {
if (i > a[in]) ++in;
b[i] = in + 1;
}
cin >> m;
... | ### Prompt
Generate a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled wit... |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int n;
cin >> n;
int arr[n];
for (int &i : arr) cin >> i;
for (long long int i = (1); i < (n); i++) {
arr[i] += arr[i - 1];
}
int q;
cin >> q;
while (q--) {
int x;
cin >> x;
int ans = lower_b... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[100005];
int n, q, x = 1, b[100005], h;
int find(int k) {
int l = 0, r = n - 1;
while (l <= r) {
h++;
int m = (l + r) / 2;
if ((a[m].first == k) || (a[m].second == k) ||
(a[m].first < k && a[m].second > k))
return m;
if (a[... | ### Prompt
Please provide a Cpp coded solution to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100000], k, l, r, c, i;
int main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> a[0];
for (i = 1; i < n; i++) {
cin >> a[i];
a[i] += a[i - 1];
}
cin >> m;
while (m--) {
cin >> k;
l = 0;
r = n - 1;
w... | ### Prompt
Develop a solution in CPP to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
const int A = 1e5 + 5;
long long int n, a[A], s[A], q, x, l, r, mid;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
s[i] = (s[i - 1] + x);
}
cin >> q;
for (int i = 1; i <= q; i++) {
cin >> x;
l = 1;
r = n;
while (l != r - 1... | ### Prompt
Construct a cpp code solution to the problem outlined:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labele... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int n, m, ans, a[N], sum, x;
map<int, int> map1;
vector<pair<int, int>> p;
set<int> set1;
int main() {
cin >> n >> a[0];
p.push_back({1, a[0]});
for (int i = 1; i < n; i++) {
cin >> a[i];
p.push_back({p[i - 1].second + 1, a[i] + p[i - 1]... | ### Prompt
Construct a CPP code solution to the problem outlined:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labele... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int numOfPils, NumOfGood;
cin >> numOfPils;
int(*arrayOfPils)[3] = new int[numOfPils][3];
int temp = 0;
for (int i = 0; i < numOfPils; i++) {
cin >> arrayOfPils[i][0];
if (i == 0) {
arrayOfPils[0][1] = 1;
arrayOfPils[0][2] = arrayO... | ### Prompt
Generate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled wit... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, t, sum(0);
cin >> n;
int counts[n];
for (int i = 0; i < n; i++) {
cin >> t;
sum += t;
counts[i] = sum;
}
int ind(0), worms[sum + 1];
for (int i = 1; i <= sum; i++) {
if (i > counts[ind]) ind++;
worms[i] = ind + 1;
}... | ### Prompt
Create a solution in Cpp for the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled w... |
#include <bits/stdc++.h>
using namespace std;
static int n, m, a, q;
static int partial[100001];
int find_position(int k) {
int a = 0;
int b = n - 1;
while (a < b) {
if (partial[(a + b + 1) / 2] >= k)
b = (a + b + 1) / 2 - 1;
else
a = (a + b + 1) / 2;
}
return a;
}
int main() {
cin >> n;... | ### Prompt
Create a solution in cpp for the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled w... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, m, j, cnt = 0, ans, x, sum = 0;
cin >> n;
int a[n], c[n];
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
c[i] = sum;
}
cin >> m;
int b[m];
for (i = 0; i < m; i++) cin >> b[i];
for (j = 0; j < m; j++) {
cout << lo... | ### Prompt
Your task is to create a Cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile a... |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
int a[MAX_N];
int q[MAX_N];
int c[2000005];
int main() {
int n, m;
cin >> n;
int s = 0;
int cnt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
for (int j = 0; j < a[i]; j++) {
c[++cnt] = i;
}
}
vector<int> v;
ci... | ### Prompt
In Cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, b[100000], a[100000], i, j = 0, k = 1, ans = 1;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
cin >> m;
for (i = 0; i < m; i++) cin >> b[i];
for (i = 1; i < n; i++) a[i] = a[i] + a[i - 1];
for (i = 0; i < m; i++) {
k = b[i];
if ... | ### Prompt
Please create a solution in CPP to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, m;
cin >> n;
long long int k[100001];
k[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a;
k[i] = k[i - 1] + a;
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> a;
int ml = 1, mr = n, mid;
while (ml <= mr) {
mid... | ### Prompt
In cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
long long binarySearch(int arr[], long long l, long long r, long long x) {
if (r > l) {
long long mid = l + (r - l) / 2;
if (arr[mid] >= x)
return binarySearch(arr, l, mid, x);
else
return binarySearch(arr, mid + 1, r, x);
} else {
return r;
... | ### Prompt
Please formulate a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, sum = 0, q;
vector<int> v;
vector<int>::iterator it;
scanf("%d", &n);
while (n--) {
scanf("%d", &x);
sum += x;
v.push_back(sum);
}
int sz = v.size();
scanf("%d", &q);
while (q--) {
scanf("%d", &x);
it = lower_boun... | ### Prompt
Please formulate a Cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m;
int a[N];
set<pair<int, int> > s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i - 1];
pair<int, int> p = {a[i], i};
s.insert(p);... | ### Prompt
Your challenge is to write a Cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
int n;
scanf("%d", &n);
vector<int> v(n), sum(n);
int prev = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &v[i]);
sum[i] = v[i] + prev;
prev = sum[i];
}
int q;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
int temp;
... | ### Prompt
Please provide a CPP coded solution to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
struct ii {
int l, r;
ii() {}
ii(int l, int r) : l(l), r(r) {}
} v[100100];
int n;
int bb(int val) {
int l = 0, r = n - 1, mid = 0;
while (l <= r) {
mid = (l + r) / 2;
if (val >= v[mid].l && val <= v[mid].r) break;
if (val < v[mid].l)
r = mid;
... | ### Prompt
Please provide a cpp coded solution to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
int n, i, a, b, j, x = 1, c, d[1000001];
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a;
for (j = x; j <= x + a - 1; j++) {
d[j] = i;
}
x = x + a;
}
cin >> b;
for (i = 1; i <= b; i++) {
cin >> a;
cout << d[a] << endl;
}
... | ### Prompt
Generate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled wit... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, sum = 0, i, j, ara[100000], mid, low, high;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &j);
sum += j;
ara[i] = sum;
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
scanf("%d", &k);
low = 0;
high = n - 1;... | ### Prompt
In Cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
long long ret = n % m;
if (ret < 0) ret += m;
return ret;
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long exp(long long a, long long b, long long m) {
if (b == 0) return 1;... | ### Prompt
Create a solution in CPP for the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled w... |
#include <bits/stdc++.h>
using namespace std;
int chk[1000002] = {0};
int g;
int main() {
int n;
cin >> n;
int a[n], suf[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
suf[0] = a[0];
int k = 1, d;
for (int j = 0; j < n; j++) {
for (int i = 0; i < a[j]; i++) chk[k++] = j + 1;
}
cin >> d;
... | ### Prompt
Please create a solution in Cpp to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
const int INF = 500000001;
const double EPS = 1e-9;
const double PI = acos(-1.0);
using namespace std;
int main() {
int n, ans[1000005];
int s, e, tmp, m, k, cnt;
while (~scanf("%d", &n)) {
k = cnt = 1;
for (int i = 0; i < n; i++) {
scanf("%d", &tmp);
for (int j = k; j... | ### Prompt
Develop a solution in cpp to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, m, sum = 0;
cin >> n;
vector<int> v(n);
for (i = 0; i < n; i++) {
cin >> v[i];
}
for (i = 1; i < n; i++) {
v[i] = v[i] + v[i - 1];
}
cin >> m;
long long b[m];
for (i = 0; i < m; i++) cin >> b[i];
for (i = 0; i < m; ... | ### Prompt
Create a solution in CPP for the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled w... |
#include <bits/stdc++.h>
using namespace std;
int presum[100005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int a[n + 1];
for (int i = 0; i < n; i++) cin >> a[i];
int su = 0;
for (int i = 0; i < n; i++) {
presum[i] = su + a[i];
su = presum[i];
}
int m;... | ### Prompt
Develop a solution in CPP to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int INF = 1e9;
const int maxn = 1e5 + 100;
struct node {
int x, id;
} q[maxn];
int n, m;
int a[maxn][2];
bool cmpx(node a, node b) { return a.x < b.x; }
bool cmpid(node a, node b) { return a.id < b.id; }
int ans[maxn];
int main() {
scanf("... | ### Prompt
In cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
int special_binary_search(int ara[], int number, int n) {
if (number <= ara[0]) return 0;
int st = 0, fn = n - 1, i, middle;
while (fn - st > 1) {
middle = (st + fn) / 2;
if (ara[middle] >= number)
fn = middle;
else
st = middle;
}
return fn... | ### Prompt
Please create a solution in Cpp to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
cout.tie(0);
int n, valore, s[100002], m, worm;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> valore;
if (i == 0)
s[1] = valore;
else
s[i + 1] = s[i] + valore;
}
cin >> m;
for (int i... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
long long int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 1; i < n; i++) arr[i] = arr[i] + arr[i - 1];
int q;
cin >> q;
while (q--) {
long lo... | ### Prompt
Generate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled wit... |
#include <bits/stdc++.h>
using namespace std;
int n;
int myf(int s, int e, int o, int sum1[]) {
int mid = (s + e) / 2;
if (mid == 0) {
if (o <= sum1[0])
return 1;
else
return 2;
} else {
if ((o <= sum1[mid]) && (o > sum1[mid - 1]))
return mid + 1;
else if (o > sum1[mid])
re... | ### Prompt
Construct a cpp code solution to the problem outlined:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labele... |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n, m, k;
while (scanf("%d", &n) != EOF) {
a[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
a[i] += a[i - 1];
}
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", &k);
printf(... | ### Prompt
Construct a Cpp code solution to the problem outlined:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labele... |
#include <bits/stdc++.h>
using namespace std;
long poz[1000005];
int main() {
long i, j, n, a, b;
cin >> n;
cin >> a;
for (i = 1; i <= a; i++) poz[i] = 1;
for (i = 1; i < n; i++) {
cin >> b;
for (j = a + 1; j <= a + b; j++) poz[j] = i + 1;
a += b;
}
cin >> n;
for (i = 0; i < n; i++) {
ci... | ### Prompt
Your task is to create a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile a... |
#include <bits/stdc++.h>
using namespace std;
struct Point {
int X;
int Y;
};
void Search(int point, Point points[], int first, int last) {
while (first <= last) {
int mid = first + (last - first) / 2;
if (point >= points[mid].X && point <= points[mid].Y) {
cout << mid + 1 << endl;
break;
... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
int binary_search(long long int a[], int n, long long int x) {
int left, right, mid;
left = 0;
right = n - 1;
while (left <= right) {
mid = (right + left) / 2;
if (a[mid] == x) return mid;
if (a[mid] > x)
right = mid - 1;
else
left = mid + 1;
}
return lef... | ### Prompt
Develop a solution in cpp to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int b, long long int e, long long int m) {
if (e == 0) return 1;
if (e % 2)
return ((b % m) * power(((b % m) * (b % m)) % m, (e - 1) / 2, m)) % m;
else
return power((b % m) * (b % m), e / 2, m) % m;
}
long long int ncr(long long i... | ### Prompt
Create a solution in cpp for the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled w... |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int n, m;
void bs(int k) {
int p = -1;
for (int i = n; i >= 1; i /= 2) {
while (p + i < n && a[p + i] <= k) p += i;
}
if (a[p] == k)
cout << p + 1 << endl;
else
cout << p + 2 << endl;
}
int main() {
int k;
cin >> n;
for (int i = 0;... | ### Prompt
Please create a solution in cpp to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int block_size = 320;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const int inf = mod;
template <typename T>
int sign(const T& a) {
if (a < 0) return -1;
if (a > 0) return 1;
return 0;
}
void... | ### Prompt
Your task is to create a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile a... |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a[(int)1e6], s[(int)1e6], x;
long long ans() {
long long st = 0, en = n - 1;
while (st < en) {
long long mid = (st + en) >> 1;
if (s[mid] >= x)
en = mid;
else
st = mid + 1;
}
return st;
}
int main() {
scanf("%I64d", &n);
f... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
int va[100010];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++) {
scanf("%d", &va[i]);
va[i] += va[i - 1];
}
int m, t;
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", &t);
printf("%... | ### Prompt
Develop a solution in cpp to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int piles[100000], n, worms, t;
int getPile(int h) {
int minn = 0;
int maxx = n;
while (maxx - minn > 1) {
int med = (maxx + minn) / 2;
if ((piles[med] >= h && med == 0) ||
(piles[med] >= h && piles[med - 1] < h))
return med + 1;
if (piles[me... | ### Prompt
Generate a Cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled wit... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, arr[1000009], j = 1, m;
memset(arr, 0, sizeof arr);
cin >> n;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
for (int k = 0; k < a; k++) {
arr[j++] = i;
}
}
cin >> m;
for (int i = 0; i < m; i++) {
int a;
cin >... | ### Prompt
Your task is to create a Cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile a... |
#include <bits/stdc++.h>
using namespace std;
long long cs[100001], a, q, i, t, s, e, m, mp, f, n;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> a;
if (i > 0)
cs[i] = cs[i - 1] + a;
else
cs[i] = a;
}
cin >> q;
while (q--) {
s = 0;
e = n - 1;
mp = 0;
m = 0;
... | ### Prompt
In cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, m, n, val, t = 0, test, arr[100000] = {0}, sum = 0;
cin >> n;
for (i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
arr[i] += arr[i - 1];
}
cin >> m;
for (i = 0; i < m; i++) {
scanf("%d", &val);
int maxi = n, mini = 1, mid;
... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
int main() {
pair<long long int, long long int> vr[100001];
int n, sum = 1;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
int temp1, temp2;
temp1 = sum;
temp2 = (a[i] + sum) - 1;
sum += a[i];
vr[i].first = temp1;
vr[i].... | ### Prompt
In Cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[1111111];
int main() {
scanf("%d", &n);
a[0] = 0;
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
a[i] = a[i - 1] + x;
}
scanf("%d", &m);
while (m--) {
int x;
int res = 0;
scanf("%d", &x);
int lef = 1, rig = n;
... | ### Prompt
Please create a solution in CPP to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
long long int n, m, i, j, k;
long long int sum = 0;
long long int b_search(long long int b[], long long int lo, long long int hi,
long long int x, long long int pos) {
if (lo > hi) {
return pos;
}
long long int mid = lo + (hi - lo) / 2;
if... | ### Prompt
Generate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled wit... |
#include <bits/stdc++.h>
using namespace std;
long long binary(long long a[], long long l, long long r, long long x) {
long long mid, ans = -1;
while (r >= l) {
mid = (l + r) / 2;
if (x <= a[mid]) {
ans = mid;
r = mid - 1;
} else
l = mid + 1;
}
return ans;
}
signed main() {
ios_b... | ### Prompt
Please create a solution in Cpp to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int binary(int st, int en, int s[], int k) {
while (en >= st) {
int mid = st + (en - st) / 2;
if (k < s[0]) {
return st;
}
if (k > s[en]) {
return en;
}
if (k == s[mid]) {
return mid;
}
if (k >= s[mid] && k <= s[mid + 1]) ... | ### Prompt
Construct a cpp code solution to the problem outlined:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labele... |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 101010;
int a[MAX_N], sum[MAX_N];
int main() {
int n, m, q;
while (scanf("%d", &n) == 1) {
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + a[i];
scanf("%d", &m);
while (m--) {
sc... | ### Prompt
Please create a solution in CPP to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, x = 1;
cin >> n;
long long int a[n];
long long int p[1000001];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
while (a[i]--) {
p[x] = i + 1;
x++;
}
}... | ### Prompt
Your challenge is to write a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100001], q, sum;
int b[1000001];
int main() {
int n, m, q, sum = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[a[i] + sum] = i;
b[1 + sum] = i;
sum += a[i];
}
cin >> m;
for (int j = 1; j <= m; j++) {
cin >> q;
if ... | ### Prompt
Please create a solution in cpp to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int binary_search(int arr[], int n, int a) {
int low, high, mid;
low = 0;
high = n - 1;
while (high > low) {
if ((low + 1) == high) {
if (arr[low] < a) return high;
return low;
}
mid = (low + high) / 2;
if (arr[mid] == a) return mid;
... | ### Prompt
Your task is to create a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile a... |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> nums(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> nums[i];
nums[i] += nums[i - 1];
}
int m, x;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> x;
int index = (int)(lower_bound(nums.begin(), nums.... | ### Prompt
Please provide a CPP coded solution to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
long long binSrc(long long arr[], long long n, long long item) {
long long mid, lo, hi;
lo = 0;
hi = n - 1;
while (lo <= hi) {
mid = (lo + hi) / 2;
if (arr[mid] == item) ... | ### Prompt
Please formulate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
int str[100009];
int main(void) {
int n, m;
scanf("%d", &n);
str[0] = 0;
for (int i = 1; i <= n; i++) {
int c;
scanf("%d", &c);
str[i] = str[i - 1] + c;
}
scanf("%d", &m);
while (m--) {
int c;
scanf("%d", &c);
if (str[n - 1] < c) {
printf("%d\n", n);
... | ### Prompt
In cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x = 0;
cin >> n;
int a[n], l[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
x += a[i];
l[i] = x;
}
cin >> m;
int q[m];
for (int i = 0; i < m; i++) {
cin >> q[i];
cout << lower_bound(l, l + n, q[i]) - l + 1 << endl;
... | ### Prompt
Please create a solution in Cpp to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void readAll(T& vec) {
for (auto& i : vec) {
cin >> i;
}
}
int binarySearch(vector<int> arr, int l, int r, int x) {
if (r >= l) {
int mid = l + (r - l) / 2;
if (arr[mid] >= x && arr[mid - 1] <= x) return mid + 1;
if (arr[mid] >= x) r... | ### Prompt
Generate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled wit... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> pilesQ, pilesAc;
for (int i = 0; i < N; i++) {
int temp;
cin >> temp;
pilesQ.push_back(temp);
}
int sum = 0;
for (int i = 0; i < pilesQ.size(); i++) {
sum += pilesQ[i];
pilesAc.push_back(sum);
}
... | ### Prompt
Create a solution in cpp for the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled w... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n;
int* a = new int[n + 1];
int* sum = new int[n + 1];
sum[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
cin >> m;
int* q = new int[m];
for (int j = 0; j < m; j++) {
cin >> q[j... | ### Prompt
In Cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x, s = 0;
vector<int> v;
cin >> n;
while (n--) {
cin >> x;
s += x;
v.push_back(s);
}
cin >> m;
while (m--) {
cin >> x;
cout << lower_bound(v.begin(), v.end(), x) - v.begin() + 1 << endl;
}
return 0;
}
| ### Prompt
Generate a Cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled wit... |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100010], sum[100010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sum[1] = 1;
for (int i = 2; i <= n; i++) sum[i] = sum[i - 1] + a[i - 1];
int q;
scanf("%d", &q);
for (; q--;) {
int x;
scanf("%d", &x);
... | ### Prompt
Generate a Cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled wit... |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long a[N];
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 1; i < n; i++) {
a[i] += a[i - 1];
}
int q;
cin >> q;
while (q--) {
int tot;
cin >> tot;
int ind = lower_bound(a, a +... | ### Prompt
Your task is to create a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile a... |
#include <bits/stdc++.h>
int num[1000010];
int main() {
int T, n, m, p;
int i, j;
int cnt = 1;
while (~scanf("%d", &T)) {
for (i = 1; i <= T; i++) {
scanf("%d", &n);
for (j = 1; j <= n; j++) num[cnt++] = i;
}
scanf("%d", &m);
for (i = 1; i <= m; i++) {
scanf("%d", &p);
pr... | ### Prompt
Please formulate a Cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, q, l;
int A[N], sum[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", A + i);
sum[i] = sum[i - 1] + A[i];
}
scanf("%d", &q);
while (q--) {
scanf("%d", &l);
printf("%d\n", lower_bound(sum, sum... | ### Prompt
Develop a solution in cpp to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
int binary(int low, int high, int c[], int b) {
int pos;
if (low > high)
pos = 0;
else {
int mid = (low + high) / 2;
if (c[mid] == b) {
pos = mid + 1;
} else if (b < c[0]) {
pos = 1;
} else if (b > c[mid] && b < c[mid + 1]) {
pos = mid + 2;
} else... | ### Prompt
Construct a CPP code solution to the problem outlined:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labele... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i == 0)
v.push_back(a[i]);
else {
v.push_back(v[v.size() - 1] + a[i]);
}
}
int m, temp;
cin >> m;
for (int i = 0; i < m; i++) ... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
inline int cmp(double x, double y = 0, double tol = 1e-10) {
return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
int main() {
int n;
scanf("%d", &n);
int v[n];
for (int i = 0; i < n; i++) scanf("%d", &v[i]);
vector<pair<int, int> > seg;
seg.push_back({1, v[0... | ### Prompt
Please create a solution in CPP to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
pair<int, int> p[200050];
int find(int t, int n) {
int l, r, m;
l = 0, r = n;
while (1) {
m = (l + r) / 2;
if (p[m].first <= t && p[m].second >= t) {
return m + 1;
}
if (p[m].first > t)
r = m;
else
l = m;
}
}
int ... | ### Prompt
Please formulate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int CUMULATIVE[300009];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool isValid(int x, int y, int n, int m) {
return x >= 0 && y >= 0 && x < n && y < m;
}
void debugMatrix(int X[][300009], int n, int m) {
int i, j;
for ((i) = (0); (i) <= (n - 1); (i) += 1) {
... | ### Prompt
Please create a solution in CPP to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i++) a[i] += a[i - 1];
int q;
cin >> q;
for (int i = 0; i < q; i++) {
int x;
cin >> x;
int val = lower_bound(a, a + n, x) - a;
... | ### Prompt
Your challenge is to write a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
struct node {
int id, x;
};
bool operator<(node a, node b) {
if (a.x < b.x)
return 1;
else
return 0;
}
int main() {
int n, m, a[100009];
node b[100009];
map<int, int> ma;
cin >> n;
a[0] = 1;
n += 1;
for (int i = 1; i < n; i++) cin >> a[i];
a[n]... | ### Prompt
Your task is to create a Cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile a... |
#include <bits/stdc++.h>
using namespace std;
void pause() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
unsigned long int n, a[100005], m, q[100005];
scanf("%d", &n);
unsigned int i;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
... | ### Prompt
Please formulate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, p = 0;
scanf("%d", &n);
vector<int> v;
for (int i = 0; i < n; i++) {
scanf("%d", &a);
v.push_back(p + a);
p += a;
}
vector<int>::iterator it;
int q, x;
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d", &x);
... | ### Prompt
Develop a solution in cpp to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int arr2[1000005] = {0};
int main() {
int arr1[100005];
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr1[i];
int x = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < arr1[i]; j++) {
arr2[x] = i + 1;
x++;
}
}
int m, y;
cin >>... | ### Prompt
Generate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled wit... |
#include <bits/stdc++.h>
using namespace std;
int A[1001000];
int main() {
int n;
cin >> n;
int sum = 0;
int tmp;
for (int i = 0; i < n; i++) {
cin >> tmp;
for (int j = sum + 1; j <= sum + tmp; j++) A[j] = i + 1;
sum += tmp;
}
int m, q;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> q;... | ### Prompt
Construct a Cpp code solution to the problem outlined:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labele... |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
long long binSrc(long long arr[], long long n, long long item) {
long long mid, lo, hi;
lo = 0;
hi = n - 1;
while (lo <= hi) {
mid = lo + ((hi - lo) / 2);
if (arr[mid] ==... | ### Prompt
Your task is to create a Cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile a... |
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 1;
int n, x, q;
int a[M];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
a[i] += x + a[i - 1];
}
scanf("%d", &q);
while (q--) {
scanf("%d", &x);
printf("%d\n", lower_bound(a, a + n, x) - a);
}
}
| ### Prompt
Please provide a Cpp coded solution to the problem described below:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pi... |
#include <bits/stdc++.h>
using namespace std;
int a, b = 0, c, z, y, l, r, t;
int main() {
cin >> a;
int A[a];
for (z = 0; z < a; z++) {
cin >> b;
if (z > 0) {
A[z] = A[z - 1] + b;
} else {
A[z] = b;
}
}
cin >> a;
int B[a];
int C[a];
for (z = 0; z < a; z++) {
cin >> B[z];... | ### Prompt
In Cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], l[maxn], r[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
a[i] = a[i - 1] + x;
l[i] = a[i - 1] + 1;
r[i] = a[i];
}
r[n + 1] = 1e9;
l[n + 1] = 1e9;
i... | ### Prompt
Please formulate a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int a[100005], s[1000005];
int main() {
int n, i, j, m, q;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
int cou = 1;
for (i = 0; i < n; i++) {
for (j = 0; j < a[i]; j++) {
s[cou++] = i + 1;
}
}
cin >> m;
for (i = 0; i < m; i++) {
... | ### Prompt
Please formulate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int A[100005];
int bsearch(int q, int l, int r) {
if (l == r - 1) {
return l;
}
int mid = (l + r) / 2;
if (A[mid - 1] < q && q <= A[mid]) {
return mid;
} else if (q <= A[mid - 1]) {
return bsearch(q, l, mid);
} else {
return bsearch(q, mid, r);
... | ### Prompt
In CPP, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
int p[100010];
p[0] = 0;
for (i = 0; i < n; i++) {
int b;
cin >> b;
p[i + 1] = p[i] + b;
}
int m;
cin >> m;
for (i = 0; i < m; i++) {
int worm;
cin >> worm;
int ans = lower_bound(p, p + n, worm) - p;... | ### Prompt
In Cpp, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
long long ara[100010];
vector<long long> v1;
long long val, sum, val1;
long long f, l, mid, mid1, res1, res2, s;
long long n, m;
void bs(long long s) {
f = 0;
l = n - 1;
while (f <= l) {
mid = (f + l) / 2;
mid1 = mid - 1;
res1 = ara[mid];
res2 = ara[mi... | ### Prompt
Please formulate a cpp solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int binary(long long int s[], int t, int m) {
int l = 0, h = m - 1;
while (l <= h) {
int mid = (l + h) / 2;
if (s[mid] == t)
return mid;
else if (l == h)
return l;
else if (t > s[mid])
l = mid + 1;
else if (t < s[mid])
h = mid... | ### Prompt
Please formulate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are lab... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, m, j, cnt = 0, ans, x, sum = 0;
cin >> n;
int a[n], c[n];
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
c[i] = sum;
}
cin >> m;
int b[m];
for (i = 0; i < m; i++) cin >> b[i];
for (j = 0; j < m; j++) {
cout << lo... | ### Prompt
Generate a CPP solution to the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled wit... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x;
vector<int> sum(n);
for (int i = 0; i < n; i++) {
cin >> x;
if (i == 0)
sum[i] = x;
else {
sum[i] = x + sum[i - 1];
}
}
int m;
cin >> m;
vector<int> j(m);
for (int i = 0; i < m; i++) cin >>... | ### Prompt
Construct a cpp code solution to the problem outlined:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labele... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long int M, k, Q, sum = 0, a = 1, W;
vector<int> x;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &W);
for (int j = 0; j < W; j++) {
x.push_back(i);
}
}
scanf("%lld", &M);
for (k = 1; k <= M; k++) {
... | ### Prompt
In CPP, your task is to solve the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int m;
cin >> m;
for (int i = 1; i < n; i++) {
v[i] += v[i - 1];
}
for (int i = 1; i <= m; i++) {
int target;
cin >> target;
int start = 0;
... | ### Prompt
Create a solution in cpp for the following problem:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are labeled w... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.