#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
typedef unsigned long long ll;
typedef pair<int, int> pi;
typedef pair<pi, vector<int>> pii;
int n, k, q, x;
ll goal[300005];
int l[300005];
int r[300005];
ll a[300005];
ll tree[1200005];
vector<int> num[300005];
int res[300005];
vector<pii> vec[100];
void update(int node, int s, int e, int l, ll v){
if(e<l||l<s) return;
if(s==e){
tree[node] += v;
return;
}
int m = (s+e)>>1;
update(node<<1, s, m, l, v);
update(node<<1|1, m+1, e, l, v);
tree[node] = tree[node<<1]+tree[node<<1|1];
}
ll query(int node, int s, int e, int l, int r){
if(e<l||r<s) return 0;
if(l<=s&&e<=r) return tree[node];
int m = (s+e)>>1;
return query(node<<1, s, m, l, r)+query(node<<1|1, m+1, e, l, r);
}
int main(){
scanf("%d %d", &n, &k);
for(int i=1;i<=k;i++){
scanf("%d", &x);
num[x].push_back(i);
}
for(int i=1;i<=n;i++) scanf("%lld", &goal[i]);
scanf("%d", &q);
vector<int> emp;
for(int i=1;i<=n;i++) emp.push_back(i);
vec[0].push_back(pii(pi(0, q-1), emp));
for(int i=0;i<q;i++) scanf("%d %d %lld", &l[i], &r[i], &a[i]);
int idx = 0;
while(!vec[idx].empty()){
for(int i=1;i<=4*k;i++) tree[i] = 0;
int prv = 0;
for(auto p: vec[idx]){
int s = p.first.first;
int e = p.first.second;
int m = (s+e)>>1;
for(int i=prv;i<=m;i++){
if(l[i]<=r[i]){
update(1, 1, k+1, l[i], a[i]);
update(1, 1, k+1, r[i]+1, -a[i]);
}
else{
update(1, 1, k+1, l[i], a[i]);
update(1, 1, k+1, k+1, -a[i]);
update(1, 1, k+1, 1, a[i]);
update(1, 1, k+1, r[i]+1, -a[i]);
}
}
prv = m+1;
if(s==e){
for(auto u: p.second){
ll sm = 0;
for(auto w: num[u]) sm += query(1, 1, k+1, 1, w);
if(sm>=goal[u]) res[u] = s;
else res[u] = -1;
}
continue;
}
vector<int> vec1;
vector<int> vec2;
for(auto u: p.second){
ll sm = 0;
for(auto w: num[u]) sm += query(1, 1, k+1, 1, w);
if(sm>=goal[u]) vec1.push_back(u);
else vec2.push_back(u);
}
vec[idx+1].push_back(pii(pi(s, m), vec1));
vec[idx+1].push_back(pii(pi(m+1, e), vec2));
}
idx++;
}
for(int i=1;i<=n;i++){
if(res[i]==-1) printf("NIE\n");
else printf("%d\n", res[i]+1);
}
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
met.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
met.cpp:47:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | for(int i=1;i<=n;i++) scanf("%lld", &goal[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~
met.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
met.cpp:52:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | for(int i=0;i<q;i++) scanf("%d %d %lld", &l[i], &r[i], &a[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7516 KB |
Output is correct |
2 |
Correct |
6 ms |
7516 KB |
Output is correct |
3 |
Correct |
6 ms |
7676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
7512 KB |
Output is correct |
2 |
Correct |
6 ms |
7516 KB |
Output is correct |
3 |
Correct |
6 ms |
7512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
236 ms |
15624 KB |
Output is correct |
2 |
Correct |
328 ms |
18372 KB |
Output is correct |
3 |
Correct |
291 ms |
17264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
280 ms |
16608 KB |
Output is correct |
2 |
Correct |
287 ms |
16616 KB |
Output is correct |
3 |
Correct |
323 ms |
17576 KB |
Output is correct |
4 |
Correct |
72 ms |
11688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
16068 KB |
Output is correct |
2 |
Correct |
207 ms |
19108 KB |
Output is correct |
3 |
Correct |
108 ms |
13192 KB |
Output is correct |
4 |
Correct |
259 ms |
18376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
300 ms |
15008 KB |
Output is correct |
2 |
Correct |
278 ms |
17520 KB |
Output is correct |
3 |
Correct |
240 ms |
15312 KB |
Output is correct |
4 |
Correct |
302 ms |
19440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2827 ms |
62160 KB |
Output is correct |
2 |
Correct |
1834 ms |
50008 KB |
Output is correct |
3 |
Correct |
605 ms |
29668 KB |
Output is correct |
4 |
Runtime error |
3071 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2896 ms |
60488 KB |
Output is correct |
2 |
Correct |
1119 ms |
49076 KB |
Output is correct |
3 |
Correct |
481 ms |
29268 KB |
Output is correct |
4 |
Runtime error |
2719 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |