# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1109726 |
2024-11-07T11:42:35 Z |
GasmaskChan |
Meteors (POI11_met) |
C++17 |
|
1704 ms |
56740 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m, q;
#define MX 300003
int owner[MX];
int need[MX];
int L[MX], R[MX];
struct event{
int l, r, val;
};
event query[MX];
struct BIT{
int n;
vector<int> bit;
BIT(int _n = 0) {
n = _n;
bit.assign(n + 2, 0);
}
void up(int p, int val){
for (; p <= n; p += p & -p){
bit[p] += val;
}
}
void updaterange(int l, int r, int v){
up(l, v);
up(r + 1, -v);
}
int get(int x){
int res = 0;
while (x){
res += bit[x];
x -= x & -x;
}
return res;
}
int single(int x){
return get(x);
}
};
vector<int> OWN[MX];
int res[MX];
void solve(){
cin >> n >> m;
for (int i = 1; i <= n; ++i) res[i] = -1;
for (int i = 1; i <= m; ++i) cin >> owner[i];
for (int i = 1; i <= n; ++i) cin >> need[i];
for (int i = 1; i <= m; ++i){
OWN[owner[i]].push_back(i);
}
cin >> q;
for (int i = 1; i <= q; ++i) cin >> query[i].l >> query[i].r >> query[i].val;
for (int i = 1; i <= n; ++i) L[i] = 1, R[i] = q;
bool process = true;
while (process){
process = false;
vector<vector<int>> G;
G.assign(q + 1, {});
BIT bit(m);
for (int i = 1; i <= n; ++i){
if (L[i] > R[i]) continue;
process = true;
G[(L[i] + R[i]) / 2].push_back(i);
}
for (int i = 1; i <= q; ++i){
event &T = query[i];
if (T.l <= T.r){
bit.updaterange(T.l, T.r, T.val);
} else {
bit.updaterange(T.l, m, T.val);
bit.updaterange(1, T.r, T.val);
}
for (int &x : G[i]){
int sum = 0;
for (int &y : OWN[x]){
if (sum >= need[x]) break;
sum += bit.single(y);
}
if (sum >= need[x]){
res[x] = i;
R[x] = i - 1;
} else {
L[x] = i + 1;
}
}
}
}
for (int i = 1; i <= n; ++i){
if (res[i] >= 0) cout << res[i] << '\n'; else
cout << "NIE" << '\n';
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(__null);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
16888 KB |
Output is correct |
2 |
Correct |
4 ms |
16720 KB |
Output is correct |
3 |
Correct |
4 ms |
16720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
16720 KB |
Output is correct |
2 |
Correct |
4 ms |
16720 KB |
Output is correct |
3 |
Correct |
5 ms |
16976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
22096 KB |
Output is correct |
2 |
Correct |
104 ms |
27360 KB |
Output is correct |
3 |
Correct |
74 ms |
22672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
22568 KB |
Output is correct |
2 |
Correct |
84 ms |
22520 KB |
Output is correct |
3 |
Correct |
106 ms |
27372 KB |
Output is correct |
4 |
Correct |
26 ms |
19016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
22108 KB |
Output is correct |
2 |
Correct |
73 ms |
27128 KB |
Output is correct |
3 |
Correct |
39 ms |
20668 KB |
Output is correct |
4 |
Correct |
75 ms |
22864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
21964 KB |
Output is correct |
2 |
Correct |
91 ms |
22564 KB |
Output is correct |
3 |
Correct |
55 ms |
22096 KB |
Output is correct |
4 |
Correct |
95 ms |
27340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1219 ms |
51124 KB |
Output is correct |
2 |
Correct |
827 ms |
41584 KB |
Output is correct |
3 |
Correct |
186 ms |
29028 KB |
Output is correct |
4 |
Correct |
1506 ms |
55412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1160 ms |
50708 KB |
Output is correct |
2 |
Correct |
683 ms |
40104 KB |
Output is correct |
3 |
Correct |
169 ms |
29000 KB |
Output is correct |
4 |
Correct |
1704 ms |
56740 KB |
Output is correct |