# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
776980 |
2023-07-08T12:56:38 Z |
borisAngelov |
Meteors (POI11_met) |
C++17 |
|
6000 ms |
36876 KB |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
int n, m, q;
long long required_sum[maxn];
struct element
{
int l;
int r;
long long x;
};
element queries[maxn];
int answer[maxn];
vector<int> positions[maxn];
struct state
{
long long sum;
long long lazy;
};
state tree[4 * maxn];
void reset_tree()
{
for (int i = 0; i < 4 * m; ++i)
{
tree[i].sum = 0;
tree[i].lazy = 0;
}
}
void push_lazy(int node, int l, int r)
{
if (tree[node].lazy != 0)
{
tree[node].sum += (1LL * (r - l + 1)) * tree[node].lazy;
if (l != r)
{
tree[2 * node].lazy += tree[node].lazy;
tree[2 * node + 1].lazy += tree[node].lazy;
}
tree[node].lazy = 0LL;
}
}
void update(int node, int l, int r, int ql, int qr, long long delta)
{
push_lazy(node, l, r);
if (l > qr || r < ql)
{
return;
}
if (ql <= l && r <= qr)
{
tree[node].lazy += delta;
push_lazy(node, l, r);
return;
}
int mid = (l + r) / 2;
update(2 * node, l, mid, ql, qr, delta);
update(2 * node + 1, mid + 1, r, ql, qr, delta);
tree[node].sum = tree[2 * node].sum + tree[2 * node + 1].sum;
}
long long point_query(int node, int l, int r, int idx)
{
push_lazy(node, l, r);
if (l == r)
{
return tree[node].sum;
}
int mid = (l + r) / 2;
if (idx <= mid)
{
return point_query(node * 2, l, mid, idx);
}
return point_query(node * 2 + 1, mid + 1, r, idx);
}
void divide(int l, int r, vector<int>& active)
{
if (l > r)
{
return;
}
int mid = (l + r) / 2;
reset_tree();
for (int i = l; i <= mid; ++i)
{
if (queries[i].l > queries[i].r)
{
update(1, 1, m, queries[i].l, m, queries[i].x);
update(1, 1, m, 1, queries[i].r, queries[i].x);
}
else
{
update(1, 1, m, queries[i].l, queries[i].r, queries[i].x);
}
}
vector<int> left_active;
vector<int> right_active;
for (int i = 0; i < active.size(); ++i)
{
int id = active[i];
long long curr_sum = 0;
for (auto pos : positions[id])
{
curr_sum += point_query(1, 1, m, pos);
if (curr_sum >= required_sum[id])
{
break;
}
}
if (curr_sum >= required_sum[id])
{
answer[id] = mid;
left_active.push_back(id);
}
else
{
required_sum[id] -= curr_sum;
right_active.push_back(id);
}
}
divide(l, mid - 1, left_active);
divide(mid + 1, r, right_active);
}
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n >> m;
for (int i = 1; i <= m; ++i)
{
int id;
cin >> id;
positions[id].push_back(i);
}
vector<int> active;
for (int i = 1; i <= n; ++i)
{
cin >> required_sum[i];
answer[i] = -1;
active.push_back(i);
}
cin >> q;
for (int i = 1; i <= q; ++i)
{
cin >> queries[i].l >> queries[i].r >> queries[i].x;
}
divide(1, q, active);
for (int i = 1; i <= n; ++i)
{
if (answer[i] == -1)
{
cout << "NIE\n";
}
else
{
cout << answer[i] << "\n";
}
}
return 0;
}
Compilation message
met.cpp: In function 'void divide(int, int, std::vector<int>&)':
met.cpp:127:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
127 | for (int i = 0; i < active.size(); ++i)
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7392 KB |
Output is correct |
2 |
Correct |
8 ms |
7508 KB |
Output is correct |
3 |
Correct |
8 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7508 KB |
Output is correct |
2 |
Correct |
7 ms |
7508 KB |
Output is correct |
3 |
Correct |
8 ms |
7508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6078 ms |
11776 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6062 ms |
11988 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6040 ms |
12064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6046 ms |
11604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6022 ms |
36876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6070 ms |
36468 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |