# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
660921 |
2022-11-23T14:30:34 Z |
rukashii |
Meteors (POI11_met) |
C++17 |
|
993 ms |
65536 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 3e5 + 2;
int n, m, a[maxn], q, tree[maxn], ans[maxn], bad[maxn];
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;
}
}
int get(int pos)
{
int 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);
memset(ans, -1, sizeof(ans));
memset(bad, -1, sizeof(bad));
//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;
int 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:86:6: warning: unused variable 'cnt' [-Wunused-variable]
86 | int cnt = n;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
21460 KB |
Output is correct |
2 |
Correct |
12 ms |
21588 KB |
Output is correct |
3 |
Correct |
12 ms |
21460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
21568 KB |
Output is correct |
2 |
Correct |
13 ms |
21468 KB |
Output is correct |
3 |
Correct |
15 ms |
21588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
24376 KB |
Output is correct |
2 |
Correct |
112 ms |
27888 KB |
Output is correct |
3 |
Correct |
93 ms |
26696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
25676 KB |
Output is correct |
2 |
Correct |
103 ms |
25932 KB |
Output is correct |
3 |
Correct |
111 ms |
28076 KB |
Output is correct |
4 |
Correct |
34 ms |
24952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
24852 KB |
Output is correct |
2 |
Correct |
105 ms |
28284 KB |
Output is correct |
3 |
Correct |
50 ms |
23080 KB |
Output is correct |
4 |
Correct |
95 ms |
27328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
23456 KB |
Output is correct |
2 |
Correct |
98 ms |
25796 KB |
Output is correct |
3 |
Correct |
74 ms |
24048 KB |
Output is correct |
4 |
Correct |
112 ms |
29444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
993 ms |
53332 KB |
Output is correct |
2 |
Correct |
666 ms |
34864 KB |
Output is correct |
3 |
Correct |
224 ms |
28972 KB |
Output is correct |
4 |
Runtime error |
985 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
958 ms |
51252 KB |
Output is correct |
2 |
Correct |
656 ms |
34872 KB |
Output is correct |
3 |
Correct |
193 ms |
27724 KB |
Output is correct |
4 |
Runtime error |
961 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |