QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#449844 | #8597. Запити красот пiдмасивiв | arbuzick# | 0 | 1094ms | 50756kb | C++20 | 2.3kb | 2024-06-21 18:15:11 | 2024-06-21 18:15:11 |
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++;
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;
}
详细
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: 6992kb
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: 0
Wrong Answer
Test #28:
score: 0
Wrong Answer
time: 1094ms
memory: 50756kb
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 20 9 5 6 7 5 7 6 6 5 7 20 6 6 7 5 7 7 7 5 9 7 6 9 5 8 20 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 20 5 7 6 7 7 6 6 5 7 6 6 6 6 6 7 20 9 20 9 7 6 6 20 9 7 20 5 9 6 7 8 9 8 9 9 8 8 5 20 8 8 6 6 6 6 6 5 9 6 6 8 20 5 9 20 6 5 7 5 20 7 20 5 20 8 6 8 7 5 6 9 6 ...
result:
wrong answer 18th numbers differ - expected: '9', found: '20'
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%