#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
const int M=3e5+5;
int o[N],al[N],ar[N],mid[N],l[N],r[N],s[N];
long long p[N],a[N],fw[N];
vector<int> ask[N];
vector<int> own[N];
void update(int idx,long long val){
if(idx==0) return;
while(idx<=M){
fw[idx]+=val;
idx+=idx & -idx;
}
}
long long read(int idx){
long long sum=0;
while(idx>0){
sum+=fw[idx];
idx-=idx & -idx;
}
return sum;
}
int main(){
int n,m,k;
cin>>n >>m;
for(int i=1;i<=m;i++) cin>>o[i],own[o[i]].push_back(i);
for(int i=1;i<=n;i++) cin>>p[i];
cin>>k;
for(int i=1;i<=k;i++) cin>>al[i] >>ar[i] >>a[i];
for(int i=1;i<=n;i++) l[i]=1,r[i]=k;
while(true){
bool up=false;
for(int i=1;i<=k;i++) ask[i].clear();
for(int i=1;i<=n;i++) mid[i]=(l[i]+r[i])/2,ask[mid[i]].push_back(i);
for(int i=0;i<=M;i++) fw[i]=0;
for(int i=1;i<=k;i++){
if(al[i]<=ar[i]) update(al[i],a[i]),update(ar[i]+1,-1*a[i]);
else update(al[i],a[i]),update(m+1,-1*a[i]),update(1,a[i]),update(ar[i]+1,-1*a[i]);
for(int j=0;j<ask[i].size();j++){
int u=ask[i][j];
long long sum=0;
for(int x=0;x<own[u].size();x++){
sum+=read(own[u][x]);
}
if(sum>=p[u]){
if(r[u]!=mid[u]) up=true;
r[u]=mid[u];
}
else{
if(l[u]!=mid[u]+1) up=true;
l[u]=mid[u]+1;
}
}
}
if(!up) break;
}
for(int i=0;i<=M;i++) fw[i]=0;
for(int i=1;i<=k;i++){
if(al[i]<=ar[i]) update(al[i],a[i]),update(ar[i]+1,-1*a[i]);
else update(al[i],a[i]),update(m+1,-1*a[i]),update(1,a[i]),update(ar[i]+1,-1*a[i]);
for(int j=0;j<ask[i].size();j++){
int u=ask[i][j];
long long sum=0;
for(int x=0;x<own[u].size();x++){
sum+=read(own[u][x]);
}
s[u]=sum;
}
}
for(int i=1;i<=n;i++){
if(s[i]<p[i]) cout<<"NIE";
else cout<<l[i];
cout<<"\n";
}
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:43:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int j=0;j<ask[i].size();j++){
| ~^~~~~~~~~~~~~~
met.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int x=0;x<own[u].size();x++){
| ~^~~~~~~~~~~~~~
met.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j=0;j<ask[i].size();j++){
| ~^~~~~~~~~~~~~~
met.cpp:68:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int x=0;x<own[u].size();x++){
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
27224 KB |
Output is correct |
2 |
Correct |
6 ms |
27352 KB |
Output is correct |
3 |
Correct |
5 ms |
27228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
27224 KB |
Output is correct |
2 |
Correct |
6 ms |
27228 KB |
Output is correct |
3 |
Correct |
7 ms |
27308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
30032 KB |
Output is correct |
2 |
Correct |
196 ms |
32852 KB |
Output is correct |
3 |
Correct |
124 ms |
32592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
31056 KB |
Output is correct |
2 |
Correct |
152 ms |
32080 KB |
Output is correct |
3 |
Correct |
202 ms |
33104 KB |
Output is correct |
4 |
Correct |
27 ms |
29268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
30544 KB |
Output is correct |
2 |
Correct |
200 ms |
33576 KB |
Output is correct |
3 |
Correct |
137 ms |
29784 KB |
Output is correct |
4 |
Correct |
124 ms |
32968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
177 ms |
29532 KB |
Output is correct |
2 |
Correct |
189 ms |
32164 KB |
Output is correct |
3 |
Correct |
108 ms |
30800 KB |
Output is correct |
4 |
Correct |
172 ms |
34164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1049 ms |
42236 KB |
Output is correct |
2 |
Incorrect |
820 ms |
38760 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1156 ms |
40920 KB |
Output is correct |
2 |
Incorrect |
780 ms |
37436 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |