#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int i, it;
struct BIT {
int n;
vector<int> tree;
void config(int _n) {
n = _n + 10;
tree.resize(_n+60);
}
void add(int p, int v) {
for(p++; p<n; p+=p&-p) tree[p] += v;
}
int query(int p) {
int ans = 0;
for(p++; p>0; p-=p&-p) ans += tree[p];
return ans;
}
int sum(int l, int r) { return query(r) - query(l-1); }
void clear() {
for(i=0; i<n+10; i++) tree[i] = 0;
}
};
struct Query { int l, r, x; };
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int> > owner(n+5);
for(i=1; i<=m; i++) {
int x;
cin >> x;
owner[x].push_back(i);
}
vector<int> req(n+5);
for(i=1; i<=n; i++) cin >> req[i];
int k;
cin >> k;
vector<Query> qus(k+1);
for(i=1; i<=k; i++)
cin >> qus[i].l >> qus[i].r >> qus[i].x;
vector<int> L(n+2, 1), R(n+2, k+1);
bool changed = true;
BIT bit;
bit.config(m+1);
vector<stack<int> > to_check(k+5);
Query q;
while(changed) {
changed = false;
bit.clear();
for(i=1; i<=n; i++)
if(L[i] != R[i]) to_check[(L[i]+R[i])/2].push(i);
for(it=1; it<=k; it++) {
q = qus[it];
if(q.l <= q.r) {
bit.add(q.l, q.x);
bit.add(q.r+1, -q.x);
} else {
bit.add(q.l, q.x);
bit.add(m+1, -q.x);
bit.add(1, q.x);
bit.add(q.r+1, -q.x);
}
while(!to_check[it].empty()) {
changed = true;
int u = to_check[it].top();
to_check[it].pop();
ll total = 0;
for(int &x : owner[u]) {
total += bit.query(x);
if(total > req[u]) break;
}
if(total >= req[u]) R[u] = it;
else L[u] = it + 1;
}
}
}
for(i=1; i<=n; i++) {
if(L[i] <= k) cout << L[i] << '\n';
else cout << "NIE\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1116 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
2 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1112 KB |
Output is correct |
2 |
Correct |
1 ms |
1116 KB |
Output is correct |
3 |
Correct |
2 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
35412 KB |
Output is correct |
2 |
Correct |
115 ms |
36652 KB |
Output is correct |
3 |
Correct |
98 ms |
35940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
35664 KB |
Output is correct |
2 |
Correct |
102 ms |
35696 KB |
Output is correct |
3 |
Correct |
107 ms |
36432 KB |
Output is correct |
4 |
Correct |
24 ms |
5208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
35096 KB |
Output is correct |
2 |
Correct |
96 ms |
36440 KB |
Output is correct |
3 |
Correct |
66 ms |
34896 KB |
Output is correct |
4 |
Correct |
94 ms |
36164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
35164 KB |
Output is correct |
2 |
Correct |
93 ms |
35548 KB |
Output is correct |
3 |
Correct |
73 ms |
35208 KB |
Output is correct |
4 |
Correct |
114 ms |
36916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
125 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
126 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |