QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#449847 | #8597. Запити красот пiдмасивiв | arbuzick# | 11 | 1520ms | 51332kb | C++20 | 2.4kb | 2024-06-21 18:17:18 | 2024-06-21 18:17:18 |
Judging History
answer
#include <bits/extc++.h>
using namespace std;
constexpr long long inf = (long long)1e18 + 7;
constexpr int maxn = 4e5 + 5;
vector<int> g[maxn];
int used[maxn];
int t = 0;
void dfs(int v) {
used[v] = t;
for (auto u : g[v]) {
if (used[u] < t) {
dfs(u);
}
}
}
void solve() {
int n, q;
cin >> n >> q;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<long long> pr_sum(n + 1);
map<int, vector<int>> pos;
pos[0].push_back(0);
for (int i = 0; i < n; ++i) {
pr_sum[i + 1] = pr_sum[i] + a[i];
pos[pr_sum[i + 1]].push_back(i + 1);
}
vector<pair<int, int>> qs(q);
vector<long long> ans(q);
vector<vector<int>> qs_ind(n + 1);
for (int i = 0; i < q; ++i) {
int tp;
cin >> tp;
cin >> qs[i].first >> qs[i].second;
qs[i].first--;
qs_ind[qs[i].second].push_back(i);
}
for (int i = 0; i < n + 1; ++i) {
g[i + n + 1].push_back(i);
}
for (auto [vl, p] : pos) {
for (int i = 1; i < (int)p.size(); ++i) {
g[p[i] + n + 1].push_back(p[i - 1] + n + 1);
}
}
for (int vl = 20; vl >= 0; --vl) {
for (int i = 0; i < n + 1; ++i) {
long long val1 = pr_sum[i] - vl;
int p = lower_bound(pos[val1].begin(), pos[val1].end(), i) - pos[val1].begin() - 1;
if (p != -1) {
g[i].push_back(pos[val1][p] + n + 1);
}
val1 = pr_sum[i] + vl;
p = lower_bound(pos[val1].begin(), pos[val1].end(), i) - pos[val1].begin() - 1;
if (p != -1) {
g[i].push_back(pos[val1][p] + n + 1);
}
}
for (auto [_, p] : pos) {
t++;
reverse(p.begin(), p.end());
for (auto ind : p) {
dfs(ind);
for (auto id : qs_ind[ind]) {
if (used[qs[id].first] == t) {
ans[id] = max(ans[id], (long long)vl);
}
}
}
}
}
for (int i = 0; i < q; ++i) {
cout << ans[i] << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1000000 1000000 548734664 631285694 511074814 185066089 177199147 524740185 143108778 954318193 103939390 194933972 126964310 977448144 188825490 775722231 460775045 254691982 436971964 566341931 148211711 74910105 923734998 440021758 474275150 717904448 680353276 612974499 712145218 300908726 34722...
output:
result:
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 22ms
memory: 7152kb
input:
1000 1000 -873807720 -737050877 797489760 406646247 -750849890 -581119106 43724194 -931326234 -9389547 -684003608 -926307185 -502569356 -461635706 -238087464 -83909772 -884633970 46721429 -576741985 -323890970 -855342249 -736506813 336516318 -4075924 -782227362 56799828 290931118 -471600723 81594380...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st numbers differ - expected: '9772834244', found: '0'
Subtask #3:
score: 0
Time Limit Exceeded
Test #14:
score: 0
Time Limit Exceeded
input:
200000 200000 580139218 -783262026 565291185 -701435432 -591602198 -342573855 -900284959 -10919966 -682899137 -282058183 963121871 491072571 691886927 761414760 -828585515 888361166 -790814084 145385324 214735368 388759807 -80339362 -975535748 522135695 301673442 36714481 785639770 319723485 1098009...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #21:
score: 0
Time Limit Exceeded
input:
200000 200000 128744308 920701830 -482412021 59142239 721167306 -622861403 165749748 -449445968 -760679479 -207234657 171482190 -239316743 75518499 -717652242 502074875 -731242646 -183939818 -625333917 -53052313 185734819 -780000096 -563390882 -690210905 596581513 764466021 776717157 -38544163 -7898...
output:
result:
Subtask #5:
score: 11
Accepted
Test #28:
score: 11
Accepted
time: 1475ms
memory: 51232kb
input:
200000 200000 3 -5 -3 3 3 -5 7 -2 2 -4 -4 9 0 -4 -2 2 -5 7 -2 3 -8 1 6 -7 9 -3 -2 4 -2 -2 3 -2 1 0 -3 6 0 -6 -2 6 -5 6 -4 3 2 -4 5 -2 -8 1 1 2 1 -3 3 5 -9 1 3 -2 0 1 -2 1 2 5 -1 -4 -1 -3 7 -7 7 1 -6 7 -1 -5 1 4 -7 6 -3 -4 -1 4 1 5 -7 -3 9 1 -6 2 -3 1 6 -1 -1 1 -1 -5 -3 9 -5 4 -1 3 -2 -4 -4 8 1 0 -9 ...
output:
9 7 8 7 8 6 5 7 9 9 7 9 6 6 9 6 8 9 9 5 6 7 5 7 6 6 5 7 8 6 6 7 5 7 7 7 5 9 7 6 9 5 8 10 5 8 7 8 5 5 8 7 7 6 6 8 6 6 9 7 8 5 6 5 8 6 6 5 5 9 8 5 7 6 7 7 6 6 5 7 6 6 6 6 6 7 9 9 8 9 7 6 6 9 9 7 8 5 9 6 7 8 9 8 9 9 8 8 5 6 8 8 6 6 6 6 6 5 9 6 6 8 9 5 9 6 6 5 7 5 10 7 5 5 6 8 6 8 7 5 6 9 6 5 10 8 8 6 6...
result:
ok 200000 numbers
Test #29:
score: 0
Accepted
time: 1499ms
memory: 51128kb
input:
200000 200000 1 2 -5 0 5 -4 4 -3 -3 0 8 -2 -8 5 2 -6 3 1 -4 9 -8 -2 0 2 6 -2 -6 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8 6 5 9 6 7 7 10 6 6 7 5 7 10 8 9 7 8 8 6 7 5 8 5 8 6 5 5 9 5 7 6 8 6 5 9 6 6 8 6 7 5 6 8 6 5 6 6 7 6 5 8 6 7 7 6 8 6 7 9 8 6 7 9 6 8 8 6 ...
result:
ok 200000 numbers
Test #31:
score: 0
Accepted
time: 1484ms
memory: 51208kb
input:
200000 200000 4 -7 4 -3 -2 5 3 -6 -1 -2 2 7 -3 -2 1 -5 6 4 -1 -3 -6 0 5 -2 -3 0 9 -3 -2 2 -1 -1 3 2 -8 1 6 -3 5 -6 -1 -1 3 -1 2 -3 4 2 -1 -5 -3 0 3 -3 2 3 -4 8 -2 -2 0 -1 1 -3 3 -5 9 -5 0 6 -8 2 -3 0 1 3 0 2 -5 4 3 -3 -5 1 7 -1 -2 -4 -1 6 0 -1 -2 4 -4 -2 -1 8 -1 1 0 0 -9 6 1 -2 3 -2 -3 1 3 2 -1 0 -6...
output:
6 6 6 9 6 6 5 7 6 7 7 9 5 9 5 5 9 6 8 5 9 6 8 7 7 7 5 5 7 8 6 8 9 8 8 8 6 6 5 8 7 9 9 5 6 7 9 5 7 5 8 7 8 6 7 5 8 6 6 8 6 5 10 5 9 8 10 9 8 9 7 9 6 6 6 6 9 5 6 7 7 5 8 6 9 5 6 5 6 7 9 6 7 8 5 9 7 8 7 7 6 5 8 6 8 7 7 8 6 7 8 9 6 6 8 7 6 8 6 7 6 7 9 7 6 9 7 6 6 8 5 6 6 9 10 8 8 7 5 9 9 8 7 6 6 7 8 6 6...
result:
ok 200000 numbers
Test #32:
score: 0
Accepted
time: 1491ms
memory: 51164kb
input:
200000 200000 -5 6 4 -7 1 -2 5 -5 7 -6 -2 0 5 2 -2 0 0 -6 1 0 6 1 1 -4 0 3 -2 0 -5 4 -3 0 6 1 -8 4 -4 2 -3 10 -7 5 -3 -4 4 -3 3 -1 1 -5 0 3 7 -10 7 -2 -2 2 -3 3 -4 8 -6 4 -2 3 -4 5 -5 -4 1 -1 9 1 -6 -3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6 7 6 8 8 8 5 ...
result:
ok 200000 numbers
Test #34:
score: 0
Accepted
time: 1520ms
memory: 51276kb
input:
200000 200000 -2 5 -6 8 -2 -8 8 -8 2 5 -7 0 8 -1 0 -2 -4 4 -5 1 7 0 -8 6 -5 0 -1 9 -3 2 -8 5 -5 8 -6 8 -2 -2 -6 1 4 0 -5 7 -6 2 2 -2 5 -7 8 1 -6 1 -5 3 6 -8 -1 5 5 -10 5 0 1 0 -1 -2 2 -1 2 3 -9 1 2 -2 2 -3 10 -7 -2 3 2 4 -10 8 -1 0 1 -8 9 1 -9 9 -3 -2 -2 2 -1 -3 4 3 -4 5 1 -7 2 -1 5 -2 1 -7 5 2 2 -1...
output:
6 6 8 9 5 6 5 6 6 7 9 6 5 8 6 6 6 7 6 6 8 6 5 7 9 8 6 7 8 8 5 8 6 8 6 6 10 7 7 6 6 5 5 7 8 6 5 5 9 8 6 6 6 6 6 6 5 9 8 8 6 6 7 6 9 8 5 6 9 6 6 6 7 9 9 9 5 10 5 7 5 7 5 6 6 8 7 6 8 6 10 7 6 5 5 9 6 7 8 5 6 7 7 8 8 7 8 7 5 5 7 8 6 6 7 7 7 7 5 6 6 5 8 6 5 7 5 7 7 7 5 6 5 7 7 7 8 9 5 5 6 8 7 6 8 5 8 5 8...
result:
ok 200000 numbers
Subtask #6:
score: 0
Skipped
Dependency #1:
0%
Subtask #7:
score: 0
Skipped
Dependency #6:
0%
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
0%