# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
660927 |
2022-11-23T14:37:44 Z |
rukashii |
Meteors (POI11_met) |
C++17 |
|
1653 ms |
65188 KB |
#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int maxn = 3e5 + 2;
long long tree[maxn];
int n, m, a[maxn], q;
vector <tuple<int, int, int>> query;
vector <int> st[maxn], check[maxn];
pair <int, int> b[maxn];
void update(int pos, int val)
{
for (int i = pos; i <= m; i += (i & (-i)))
{
tree[i] += val;
}
}
long long get(int pos)
{
long long ret = 0;
for (int i = pos; i >= 1; i -= (i & (-i)))
{
ret += tree[i];
}
return ret;
}
void query_apply(int i)
{
auto [u, v, f] = query[i - 1];
if (u <= v)
{
update(u, f);
update(v + 1, -f);
}
else
{
update(1, f);
update(v + 1, -f);
update(u, f);
}
}
signed main()
{
ios::sync_with_stdio(0); cin.tie(0);
//freopen("input.inp", "r", stdin);
//freopen("output.out", "w", stdout);
cin >> n >> m;
for (int i = 1, t; i <= m; i++)
{
cin >> t;
st[t].push_back(i);
}
for (int i = 1; i <= n; i++)
cin >> a[i];
cin >> q;
for (int i = 1; i <= q; i++)
{
int l, r, w;
cin >> l >> r >> w;
query.push_back({l, r, w});
}
for (int i = 1; i <= n; i++)
{
b[i] = {1, q + 1};
}
int cnt = n;
while (1)
{
bool kt = 0;
memset(tree, 0, sizeof(tree));
for (int i = 1; i <= q; i++)
check[i].clear();
for (int i = 1; i <= n; i++)
{
auto [l, r] = b[i];
if (l < r)
{
int mid = (l + r) / 2;
check[mid].push_back(i);
kt = 1;
}
}
if (!kt)
break;
for (int i = 1; i <= q; i++)
{
query_apply(i);
for (int p : check[i])
{
int &l = b[p].first, &r = b[p].second;
int mid = (l + r) / 2;
long long sum = 0;
for (int child : st[p])
{
sum += get(child);
if (sum >= a[p])
break;
}
if (sum < a[p])
{
l = mid + 1;
}
else
{
r = mid;
}
}
}
}
for (int i = 1; i <= n; i++)
if (b[i].second <= q)
cout << b[i].second << '\n';
else
cout << "NIE\n";
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:83:6: warning: unused variable 'cnt' [-Wunused-variable]
83 | int cnt = n;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16724 KB |
Output is correct |
2 |
Correct |
10 ms |
16724 KB |
Output is correct |
3 |
Correct |
10 ms |
16724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16724 KB |
Output is correct |
2 |
Correct |
10 ms |
16820 KB |
Output is correct |
3 |
Correct |
10 ms |
16852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
18044 KB |
Output is correct |
2 |
Correct |
97 ms |
20072 KB |
Output is correct |
3 |
Correct |
92 ms |
19744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
19144 KB |
Output is correct |
2 |
Correct |
94 ms |
19236 KB |
Output is correct |
3 |
Correct |
107 ms |
20244 KB |
Output is correct |
4 |
Correct |
33 ms |
18468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
18628 KB |
Output is correct |
2 |
Correct |
83 ms |
20664 KB |
Output is correct |
3 |
Correct |
48 ms |
17404 KB |
Output is correct |
4 |
Correct |
92 ms |
20160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
17760 KB |
Output is correct |
2 |
Correct |
87 ms |
19112 KB |
Output is correct |
3 |
Correct |
72 ms |
17948 KB |
Output is correct |
4 |
Correct |
108 ms |
21432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
854 ms |
34040 KB |
Output is correct |
2 |
Correct |
558 ms |
22088 KB |
Output is correct |
3 |
Correct |
218 ms |
19860 KB |
Output is correct |
4 |
Correct |
1448 ms |
61220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
872 ms |
32688 KB |
Output is correct |
2 |
Correct |
641 ms |
22088 KB |
Output is correct |
3 |
Correct |
185 ms |
19232 KB |
Output is correct |
4 |
Correct |
1653 ms |
65188 KB |
Output is correct |