# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
715126 |
2023-03-26T00:07:21 Z |
aryan12 |
Meteors (POI11_met) |
C++17 |
|
960 ms |
51048 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
const int N = 3e5 + 5;
vector<int> bit(N);
int n, m;
void Update(int pos, int val)
{
for(int i = pos; i > 0; i -= (i & (-i)))
{
bit[i] += val;
}
}
int Query(int pos)
{
if(pos == 0) return 0;
int ans = 0;
for(int i = pos; i < n + 5; i += (i & (-i)))
{
ans += bit[i];
}
return ans;
}
void Update(int l, int r, int val)
{
if(r < l)
{
Update(r, val);
// cout << "Update(" << r << ", " << val << ")\n";
r = m;
}
// cout << "Update(" << r << ", " << val << ")\n";
Update(r, val);
// cout << "Update(" << l - 1 << ", " << -val << ")\n";
Update(l - 1, -val);
}
void Solve()
{
cin >> n >> m;
bit.resize(n + 5);
vector<int> sector[n + 1];
vector<int> requirements(n + 1);
for(int i = 1; i <= m; i++)
{
int x;
cin >> x;
// cout << "x = " << x << ", i = " << i << "\n";
sector[x].push_back(i);
}
for(int i = 1; i <= n; i++)
{
bit[i] = 0;
cin >> requirements[i];
}
bit[0] = 0;
int k;
cin >> k;
vector<array<int, 3> > queries(k + 1);
vector<array<int, 3> > ranges(n + 1);
vector<int> middle[k + 1];
for(int i = 1; i <= k; i++)
{
cin >> queries[i][0] >> queries[i][1] >> queries[i][2];
}
for(int i = 1; i <= n; i++)
{
ranges[i] = {1, k, k + 1};
}
while(true)
{
int cnt = 0;
for(int i = 0; i <= k; i++)
{
middle[i].clear();
}
for(int i = 0; i < n + 5; i++)
{
bit[i] = 0;
}
for(int i = 1; i <= n; i++)
{
if(ranges[i][0] > ranges[i][1])
{
cnt++;
}
else
{
int mid = (ranges[i][0] + ranges[i][1]) / 2;
// cout << "i = " << i << ", ranges[i][0] = " << ranges[i][0] << ", ranges[i][1] = " << ranges[i][1] << ", mid = " << mid << endl;
middle[mid].push_back(i);
}
}
if(cnt == n)
{
break;
}
for(int i = 1; i <= k; i++)
{
Update(queries[i][0], queries[i][1], queries[i][2]);
// for(int j = 1; j <= m; j++)
// {
// cout << Query(j) << " ";
// }
// cout << "\n";
for(int j: middle[i])
{
int f = 0, gathered = 0;
for(int cur: sector[j])
{
gathered += Query(cur);
// cout << "Query(cur) = " << Query(cur) << "\n";
// cout << "position = " << cur << ", gathered = " << gathered << "\n";
if(gathered >= requirements[j])
{
ranges[j][1] = i - 1;
ranges[j][2] = i;
f = 1;
break;
}
}
// cout << "gathered = " << gathered << ", query number = " << i << ", organization number = " << j << "\n";
if(f == 0)
{
ranges[j][0] = i + 1;
}
}
}
}
for(int i = 1; i <= n; i++)
{
if(ranges[i][2] == k + 1)
{
cout << "NIE\n";
}
else
{
cout << ranges[i][2] << "\n";
}
}
}
int32_t main()
{
auto begin = std::chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
for(int i = 1; i <= t; i++)
{
//cout << "Case #" << i << ": ";
Solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
2696 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2780 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
7472 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
8624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
7472 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
55 ms |
6584 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
960 ms |
51048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
827 ms |
47840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |