# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
776991 |
2023-07-08T13:06:23 Z |
borisAngelov |
Meteors (POI11_met) |
C++17 |
|
6000 ms |
45248 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 = l; i <= mid; ++i)
{
increase(queries[i].l, queries[i].r, queries[i].x);
}
vector<int> to_clear;
for (int i = 1; i <= m; ++i)
{
preffix[i] += preffix[i - 1];
if (preffix[i] != 0)
{
to_clear.push_back(i);
}
}
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);
}
}
for (auto pos : to_clear)
{
preffix[pos] = 0LL;
}
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:70:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int i = 0; i < active.size(); ++i)
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7380 KB |
Output is correct |
2 |
Correct |
7 ms |
7524 KB |
Output is correct |
3 |
Correct |
7 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
7508 KB |
Output is correct |
2 |
Correct |
7 ms |
7508 KB |
Output is correct |
3 |
Correct |
7 ms |
7520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6056 ms |
12528 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6025 ms |
12872 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6021 ms |
12272 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6008 ms |
12604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6027 ms |
45248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
6026 ms |
44776 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |