#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fi first
#define se second
#define ld long double
#define n_4 10010
#define n_5 100010
#define n_6 1000010
#define n_7 10000010
#define n_8 100000010
#define pii pair<int,int>
#define pll pair<long long,long long>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ld, null_type,less<ld>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key -> # less than k
// find_by_order -> k-th element
// pq max element
const int NMAX = 300010;
int N, M, K, l[NMAX], r[NMAX], L[NMAX], R[NMAX], res[NMAX];
ll bit[NMAX], potrebno[NMAX], x[NMAX];
vector<int>sec[NMAX];
vector<int>q[NMAX];
void update(int ind, ll koliko) {
while(ind < NMAX) {
bit[ind] += koliko;
ind += ind&-ind;
}
}
ll query(int ind) {
ll sum = 0;
while(ind > 0) {
sum += bit[ind];
ind -= ind&-ind;
}
return sum;
}
void solve() {
cin >> N >> M;
for (int i = 1 ; i <= M ; i++ ) {
int o;
cin >> o;
sec[o].pb(i);
}
for (int i = 1 ; i <= N ; i++ ) {
int p ;
cin >> p;
potrebno[i] = p;
}
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;
res[i] = K+1;
//cout << sec[i].size() << endl;
}
bool changed = 1;
while(changed) {
changed = 0;
fill(bit, bit+NMAX, 0LL);
for (int i = 1 ; i <= K ; i++ ) q[i].clear();
for (int i = 1 ; i <= N ; i++ ) {
if ( L[i] <= R[i] ) {
changed = 1;
int mid = (L[i] + R[i])/2;
q[mid].pb(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]);
}
for (int u : q[i]) {
ll sum = 0;
for (int s : sec[u]) {
sum += query(s);
if ( sum >= potrebno[u] ) break;
}
if ( sum >= potrebno[u] ) {
res[u] = i;
R[u] = i-1;
}
else L[u] = i+1;
//cout << i << ' ' << u << ' ' << sum << endl ;
}
}
}
for (int i = 1 ; i <= N ; i++ ) {
//cout << L[i] << ' ' << R[i] << ' ';
if ( res[i] == K+1 ) {
puts("NIE");
}
else cout << res[i] << endl ;
}
}
int main () {
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
16716 KB |
Output is correct |
2 |
Correct |
14 ms |
16828 KB |
Output is correct |
3 |
Correct |
14 ms |
16828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
16716 KB |
Output is correct |
2 |
Correct |
14 ms |
16716 KB |
Output is correct |
3 |
Correct |
13 ms |
16844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
18404 KB |
Output is correct |
2 |
Correct |
203 ms |
20484 KB |
Output is correct |
3 |
Correct |
177 ms |
20072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
19424 KB |
Output is correct |
2 |
Correct |
190 ms |
19516 KB |
Output is correct |
3 |
Correct |
234 ms |
20548 KB |
Output is correct |
4 |
Correct |
65 ms |
18836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
160 ms |
18872 KB |
Output is correct |
2 |
Correct |
246 ms |
21088 KB |
Output is correct |
3 |
Correct |
155 ms |
17588 KB |
Output is correct |
4 |
Correct |
195 ms |
20420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
171 ms |
17860 KB |
Output is correct |
2 |
Correct |
192 ms |
19444 KB |
Output is correct |
3 |
Correct |
140 ms |
18244 KB |
Output is correct |
4 |
Correct |
242 ms |
21808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1548 ms |
35824 KB |
Output is correct |
2 |
Correct |
994 ms |
22728 KB |
Output is correct |
3 |
Correct |
837 ms |
21052 KB |
Output is correct |
4 |
Correct |
2433 ms |
56072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1551 ms |
34320 KB |
Output is correct |
2 |
Correct |
1014 ms |
22680 KB |
Output is correct |
3 |
Correct |
688 ms |
20128 KB |
Output is correct |
4 |
Correct |
2631 ms |
62968 KB |
Output is correct |