#include<bits/stdc++.h>
#define pb push_back
#define f first
#define ll long long
#define s second
using namespace std;
const int N=3e5+5;
ll fw[N];
void add(int i,ll amt){
for(;i<N;i+=i&-i)fw[i]+=amt;
}
ll qr(int i,ll res=0){
for(;i;i-=i&-i)res+=fw[i];
return res;
}
vector<ll>g[N];
vector<ll>now[N];
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int n,m;cin>>n>>m;
ll a[n+1];
ll b[m+1];
ll c[n+1];
for(int i=1;i<=m;i++)cin>>b[i],g[b[i]].pb(i);
for(int i=1;i<=n;i++)cin>>c[i];
int k;cin>>k;
pair<ll,pair<int,int>>q[k+1];
for(int i=1;i<=k;i++)cin>>q[i].s.f>>q[i].s.s>>q[i].f;
int l[n+1],r[n+1];
for(int i=1;i<=n;i++)l[i]=1,r[i]=k+1;
while(1){
memset(fw,0,sizeof fw);
int cnt=0;
for(int i=1;i<=n;i++){
if(l[i]==r[i])continue;
cnt++;now[(l[i]+r[i])/2].pb(i);
}if(cnt==0)break;
for(int i=1;i<=k;i++){
if(q[i].s.f<=q[i].s.s)add(q[i].s.f,q[i].f),add(q[i].s.s+1,-q[i].f);
else add(q[i].s.f,q[i].f),add(1,q[i].f),add(q[i].s.s+1,-q[i].f);
for(auto it : now[i]){
ll sum=0;
for(auto ij : g[it])sum+=qr(ij);
if(sum>c[it])r[it]=i;
else l[it]=i+1;
}now[i].clear();
}
}for(int i=1;i<=n;i++){
if(r[i]>k)cout<<"NIE\n";
else cout<<r[i]<<"\n";
}
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:21:8: warning: unused variable 'a' [-Wunused-variable]
21 | ll a[n+1];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
16728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
16732 KB |
Output is correct |
2 |
Correct |
5 ms |
16732 KB |
Output is correct |
3 |
Incorrect |
6 ms |
16988 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
19344 KB |
Output is correct |
2 |
Incorrect |
102 ms |
22400 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
83 ms |
20820 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
90 ms |
19740 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
18620 KB |
Output is correct |
2 |
Correct |
103 ms |
20824 KB |
Output is correct |
3 |
Correct |
66 ms |
19024 KB |
Output is correct |
4 |
Incorrect |
97 ms |
24020 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
772 ms |
46988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
763 ms |
44996 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |