# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
776987 |
2023-07-08T13:02:22 Z |
borisAngelov |
Meteors (POI11_met) |
C++17 |
|
6000 ms |
20552 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];
long long preffix[maxn];
void increase(int l, int r, long long delta)
{
if (l <= r)
{
preffix[l] += delta;
preffix[r + 1] -= delta;
}
else
{
preffix[1] += delta;
preffix[r + 1] -= delta;
preffix[l] += delta;
}
}
void divide(int l, int r, vector<int>& active)
{
if (l > r)
{
return;
}
int mid = (l + r) / 2;
for (int i = 1; i <= m; ++i)
{
preffix[i] = 0LL;
}
for (int i = l; i <= mid; ++i)
{
increase(queries[i].l, queries[i].r, queries[i].x);
}
for (int i = 1; i <= m; ++i)
{
preffix[i] += preffix[i - 1];
}
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 += preffix[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:68:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for (int i = 0; i < active.size(); ++i)
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7380 KB |
Output is correct |
2 |
Correct |
7 ms |
7380 KB |
Output is correct |
3 |
Correct |
6 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
6 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5643 ms |
9344 KB |
Output is correct |
2 |
Correct |
5637 ms |
12496 KB |
Output is correct |
3 |
Correct |
5641 ms |
10616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5607 ms |
9364 KB |
Output is correct |
2 |
Correct |
5619 ms |
10500 KB |
Output is correct |
3 |
Correct |
5589 ms |
11880 KB |
Output is correct |
4 |
Correct |
582 ms |
9592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5537 ms |
9244 KB |
Output is correct |
2 |
Correct |
5571 ms |
12156 KB |
Output is correct |
3 |
Correct |
69 ms |
8764 KB |
Output is correct |
4 |
Correct |
5607 ms |
10840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5585 ms |
9016 KB |
Output is correct |
2 |
Correct |
5593 ms |
10464 KB |
Output is correct |
3 |
Correct |
5618 ms |
10012 KB |
Output is correct |
4 |
Correct |
5615 ms |
11560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6058 ms |
20552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6063 ms |
20080 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |