#include<bits/stdc++.h>
//#define int long long
using namespace std;
int own[350005];
vector<int>states[350005];
int least[350005];
struct fenwick{
long long info[350005];
void upd(int x,long long val){
for(int i=x;i<=350001;i+=i&-i)info[i]+=val;
}
long long fval(int x){
long long sum=0;
for(int i=x;i>0;i-=i&-i)sum+=info[i];
return sum;
}
void clear(){
for(int i=1;i<=350001;i++)info[i]=0;
}
}tr;
int st[350005];
int en[350005];
struct meteor{
int l,r,a;
meteor(int x,int y,int z){
l=x,r=y,a=z;
}
};
vector<meteor>events;
vector<int>query[350005];
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>own[i];
states[own[i]].push_back(i);
}
for(int i=1;i<=n;i++){
cin>>least[i];
}
int k;cin>>k;
long long a,b,c,md,cur,l,r,sum,x;
for(int i=1;i<=k;i++){
a,b,c;cin>>a>>b>>c;
events.push_back(meteor(a,b,c));
}
for(int i=1;i<=n;i++){
st[i]=1;en[i]=k+1;
md=(st[i]+en[i])/2;
query[md].push_back(i);
}
//cout<<"work\n";
while(1){
cur=0;
for(auto x:events){
cur++;
//cout<<"EVENT:"<<cur<<"\n";
l=x.l;
r=x.r;
if(l<=r)tr.upd(l,x.a),tr.upd(r+1,x.a*-1);
else tr.upd(l,x.a),tr.upd(m+1,x.a*-1),tr.upd(1,x.a),tr.upd(r+1,x.a*-1);
for(auto y:query[cur]){
//cerr<<"STATE:"<<y<<"\n";
sum=0;
for(auto z:states[y]){
//cerr<<"STATION:"<<z<<" "<<tr.fval(1,m,1,z)<<"\n";
sum+=tr.fval(z);
if(sum>=least[y])break;
}
if(sum>=least[y]){
//cerr<<"ENOUGH\n";
en[y]=cur;
}else{
//cerr<<"NOT ENOUGH\n";
st[y]=cur+1;
}
}
query[cur].clear();
}
tr.clear();
int check=1;
for(int i=1;i<=n;i++){
if(st[i]!=en[i]){
check=0;
md=(st[i]+en[i])/2;
query[md].push_back(i);
}
}
if(check)break;
}
for(int i=1;i<=n;i++){
x=st[i];
if(x==k+1)cout<<"NIE\n";
else cout<<x<<"\n";
}
}
Compilation message
met.cpp: In function 'int32_t main()':
met.cpp:45:9: warning: left operand of comma operator has no effect [-Wunused-value]
45 | a,b,c;cin>>a>>b>>c;
| ^
met.cpp:45:13: warning: right operand of comma operator has no effect [-Wunused-value]
45 | a,b,c;cin>>a>>b>>c;
| ^
met.cpp:45:14: warning: right operand of comma operator has no effect [-Wunused-value]
45 | a,b,c;cin>>a>>b>>c;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
23644 KB |
Output is correct |
2 |
Correct |
8 ms |
23644 KB |
Output is correct |
3 |
Correct |
9 ms |
23644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
23644 KB |
Output is correct |
2 |
Correct |
7 ms |
23644 KB |
Output is correct |
3 |
Correct |
7 ms |
23640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
25044 KB |
Output is correct |
2 |
Correct |
135 ms |
26824 KB |
Output is correct |
3 |
Correct |
88 ms |
26568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
107 ms |
26164 KB |
Output is correct |
2 |
Correct |
106 ms |
26308 KB |
Output is correct |
3 |
Correct |
125 ms |
26960 KB |
Output is correct |
4 |
Correct |
26 ms |
25524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
25552 KB |
Output is correct |
2 |
Correct |
109 ms |
27500 KB |
Output is correct |
3 |
Correct |
115 ms |
24472 KB |
Output is correct |
4 |
Correct |
91 ms |
27116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
24836 KB |
Output is correct |
2 |
Correct |
110 ms |
26060 KB |
Output is correct |
3 |
Correct |
66 ms |
25036 KB |
Output is correct |
4 |
Correct |
127 ms |
28244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
835 ms |
41912 KB |
Output is correct |
2 |
Correct |
653 ms |
31688 KB |
Output is correct |
3 |
Correct |
619 ms |
26824 KB |
Output is correct |
4 |
Correct |
1315 ms |
65536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
771 ms |
40212 KB |
Output is correct |
2 |
Correct |
630 ms |
30280 KB |
Output is correct |
3 |
Correct |
503 ms |
26044 KB |
Output is correct |
4 |
Correct |
1451 ms |
65536 KB |
Output is correct |