#include <bits/stdc++.h>
#define MAXN 300010
#define MAXBIN 19
#define MAXV 300000
#define lld long long
#define endl '\n'
#define PRINT(x) cerr<<flush<<#x<<'='<<x<<endl;
using namespace std;
int N, M, K, l[MAXN], r[MAXN], L[MAXN], R[MAXN], rez[MAXN];
lld bit[MAXN], p[MAXN], x[MAXN];
vector<int> sec[MAXN], q[MAXN];
void update(int idx, lld val) {
while(idx < MAXN) {
bit[idx] += val;
idx += idx&-idx;
}
}
lld query(int idx) {
lld sum = 0;
while(idx) {
sum += bit[idx];
idx -= idx&-idx;
}
return sum;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> M;
for(int i = 1; i <= M; i++) {
int o; cin >> o;
sec[o].push_back(i);
}
for(int i = 1; i <= N; i++) cin >> p[i];
cin >> K;
for(int i = 1; i <= K; i++) {
cin >> l[i] >> r[i] >> x[i];
}
for(int i = 1; i <= N; i++) {
L[i] = 1, R[i] = K, rez[i] = K+1;
}
int t = MAXBIN;
while(t--) {
fill(bit, bit+MAXN, 0);
for(int i = 1; i <= K+1; i++) q[i].clear();
for(int i = 1; i <= N; i++) {
if(L[i] <= R[i]) {
int mid = (L[i]+R[i])/2;
q[mid].push_back(i);
}
}
for(int i = 1; i <= K; i++) {
if(l[i] <= r[i]) {
update(l[i], x[i]);
update(r[i]+1, -x[i]);
} else {
update(1, x[i]);
update(r[i]+1, -x[i]);
update(l[i], x[i]);
update(M+1, -x[i]);
}
for(auto x : q[i]) {
lld sum = 0;
for(int s : sec[x]) {
sum += query(s);
}
if(sum >= p[x]) {
R[x] = i-1;
rez[x] = i;
} else {
L[x] = i+1;
}
}
}
}
for(int i = 1; i <= N; i++) {
if(rez[i] == K+1) cout << "NIE" << endl;
else cout << rez[i] << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
16844 KB |
Output is correct |
2 |
Correct |
17 ms |
16972 KB |
Output is correct |
3 |
Correct |
18 ms |
16776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
16864 KB |
Output is correct |
2 |
Correct |
15 ms |
16856 KB |
Output is correct |
3 |
Correct |
16 ms |
16932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
19160 KB |
Output is correct |
2 |
Correct |
194 ms |
21764 KB |
Output is correct |
3 |
Correct |
150 ms |
21104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
161 ms |
20556 KB |
Output is correct |
2 |
Correct |
166 ms |
20536 KB |
Output is correct |
3 |
Correct |
233 ms |
21852 KB |
Output is correct |
4 |
Correct |
46 ms |
19148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
128 ms |
19664 KB |
Output is correct |
2 |
Correct |
219 ms |
22388 KB |
Output is correct |
3 |
Correct |
190 ms |
18428 KB |
Output is correct |
4 |
Correct |
144 ms |
21636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
166 ms |
18808 KB |
Output is correct |
2 |
Correct |
181 ms |
20756 KB |
Output is correct |
3 |
Correct |
125 ms |
19208 KB |
Output is correct |
4 |
Correct |
181 ms |
23072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1080 ms |
43552 KB |
Output is correct |
2 |
Incorrect |
782 ms |
30608 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1101 ms |
42024 KB |
Output is correct |
2 |
Incorrect |
730 ms |
29028 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |