#include<bits/stdc++.h>
using namespace std;
const int MXN=300005;
int n,m,k;
int target[MXN],L[MXN],R[MXN];
vector<int> child[MXN];
vector<tuple<int,int,int>> shower;
long long fw[MXN];
vector<int> ask[MXN];
void upd(int x,int val){
for(int i=x;i<=300000;i+=i&-i)
fw[i]+=val;
}
long long qr(int x){
long long sum=0;
for(int i=x;i>=1;i-=i&-i)
sum+=fw[i];
return sum;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i=1,x;i<=m;i++){
cin >> x;
child[x].push_back(i);
}
for(int i=1;i<=n;i++)
cin >> target[i];
cin >> k;
for(int i=1,x,y,z;i<=k;i++){
cin >> x >> y >> z;
shower.push_back({x,y,z});
}
for(int i=1;i<=n;i++){
L[i]=1;
R[i]=k+1;
}
while(1){
bool done=1;
for(int i=1;i<=n;i++){
if(L[i]<R[i]){
done=0;
ask[(L[i]+R[i])/2].push_back(i);
}
}
if(done)
break;
memset(fw,0,sizeof(fw));
for(int i=1;i<=k;i++){
auto [l,r,a]=shower[i-1];
if(l<=r){
upd(l,a);
upd(r+1,-a);
}
else{
upd(l,a);
upd(1,a);
upd(r+1,-a);
}
for(auto it:ask[i]){
long long sum=0;
for(auto iit:child[it]){
sum+=qr(iit);
if(sum>=target[it])
break;
}
if(sum>=target[it])
R[it]=i;
else
L[it]=i+1;
}
ask[i].clear();
}
}
for(int i=1;i<=n;i++){
if(L[i]<=k)
cout << L[i] << "\n";
else
cout << "NIE\n";
}
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:57:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
57 | auto [l,r,a]=shower[i-1];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16724 KB |
Output is correct |
2 |
Correct |
10 ms |
16724 KB |
Output is correct |
3 |
Correct |
14 ms |
16752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
16832 KB |
Output is correct |
2 |
Correct |
10 ms |
16724 KB |
Output is correct |
3 |
Correct |
12 ms |
16792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
18168 KB |
Output is correct |
2 |
Correct |
134 ms |
20040 KB |
Output is correct |
3 |
Correct |
109 ms |
19704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
117 ms |
19256 KB |
Output is correct |
2 |
Correct |
118 ms |
19260 KB |
Output is correct |
3 |
Correct |
120 ms |
20220 KB |
Output is correct |
4 |
Correct |
33 ms |
18480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
18576 KB |
Output is correct |
2 |
Correct |
180 ms |
20704 KB |
Output is correct |
3 |
Correct |
120 ms |
17416 KB |
Output is correct |
4 |
Correct |
113 ms |
20092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
17784 KB |
Output is correct |
2 |
Correct |
128 ms |
19120 KB |
Output is correct |
3 |
Correct |
79 ms |
17952 KB |
Output is correct |
4 |
Correct |
122 ms |
21436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
883 ms |
33900 KB |
Output is correct |
2 |
Correct |
594 ms |
22080 KB |
Output is correct |
3 |
Correct |
552 ms |
22212 KB |
Output is correct |
4 |
Correct |
1532 ms |
61228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
875 ms |
32672 KB |
Output is correct |
2 |
Correct |
626 ms |
22080 KB |
Output is correct |
3 |
Correct |
485 ms |
22612 KB |
Output is correct |
4 |
Correct |
1720 ms |
65128 KB |
Output is correct |