# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
496683 | Elias | Sum Zero (RMI20_sumzero) | C++17 | 796 ms | 65536 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 <bits/stdc++.h>
using namespace std;
struct Range
{
int s, e;
};
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> v(n);
int last = 0;
for (int &i : v)
{
cin >> i;
i = last += i;
}
vector<Range> ranges;
map<int, int> brr;
brr[0] = -1;
for (int i = 0; i < n; i++)
{
auto x = brr.find(v[i]);
if (x != brr.end())
ranges.push_back(Range{(*x).second + 1, i});
brr[v[i]] = i;
}
int j = 0;
vector<vector<int>> jump(n + 2, vector<int>(25, n + 1));
jump[n][0] = n + 1;
for (int i = 0; i < n; i++)
{
while (ranges[j].s < i)
if (++j >= ranges.size())
goto exit;
jump[i][0] = ranges[j].e + 1;
}
exit:
for (int j = 1; j < 25; j++)
for (int i = 0; i < n; i++)
jump[i][j] = jump[jump[i][j - 1]][j - 1];
int q;
cin >> q;
while (q--)
{
int a, b;
cin >> a >> b;
a--;
int num = 0;
for (int j = 24; j >= 0; j--)
{
if (jump[a][j] <= b)
{
num += (1 << j);
a = jump[a][j];
}
}
cout << num << "\n";
}
}
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... |