#include<bits/stdc++.h>
#define N 300100
#define rep(i,j,k) for(I i=j;i<=k;i++)
using namespace std;
#define I long long
I bit[N],ans[N],L[N],R[N],a[N];
struct c{I g, id;vector<I>st;};
void u(I x, I y) {
for(;x<N;x+=x&-x)
bit[x]+=y;
}
void upd(I l, I r, I x) {
u(l,x),u(r+1,-x);
if(l>r)u(1,x);
}
I q(I x) {
I r = 0;
while(x)r+=bit[x],x-=x&-x;
return r;
}
c X[N];
void solve(I l, I r, vector<int> cs){
if(l==r) {
for(auto i: cs) ans[X[i].id] = l;
l++;
}
if(cs.empty()||l>r) return;
I m=l+r>>1;
rep(i,l,m)
upd(L[i],R[i],a[i]);
vector<int>c1,c2;
for(auto i: cs) {
I x=0;
for(auto j:X[i].st)x+=q(j);
if(x<X[i].g) X[i].g-=x,c2.push_back(i);
else c1.push_back(i);
}
cs.clear();
rep(i,l,m) upd(L[i],R[i],-a[i]);
solve(l,m,c1);
solve(m+1,r,c2);
}
int main() {
I n,m,k;
cin>>n>>m;
vector<int> v(n);
iota(v.begin(),v.end(),0);
rep(i,1,m){
I x;
cin>>x;
X[x-1].st.push_back(i);
}
rep(i,0,n-1)cin>>X[i].g,X[i].id=i+1;
cin>>k;
rep(i,1,k)cin>>L[i]>>R[i]>>a[i];
L[k+1]=1,R[k+1]=m,a[k+1]=1e18;
solve(1,k+1,v);
rep(i,1,n)
if(ans[i]<=k) cout << ans[i] <<'\n';
else cout << "NIE\n";
}
Compilation message
met.cpp: In function 'void solve(long long int, long long int, std::vector<int>)':
met.cpp:28:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | I m=l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12116 KB |
Output is correct |
2 |
Correct |
8 ms |
12116 KB |
Output is correct |
3 |
Correct |
8 ms |
12116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
12076 KB |
Output is correct |
2 |
Correct |
8 ms |
12188 KB |
Output is correct |
3 |
Correct |
11 ms |
12244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
14968 KB |
Output is correct |
2 |
Correct |
137 ms |
17848 KB |
Output is correct |
3 |
Correct |
145 ms |
14988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
14660 KB |
Output is correct |
2 |
Correct |
138 ms |
14704 KB |
Output is correct |
3 |
Correct |
105 ms |
16604 KB |
Output is correct |
4 |
Correct |
49 ms |
14460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
14696 KB |
Output is correct |
2 |
Correct |
191 ms |
16856 KB |
Output is correct |
3 |
Correct |
74 ms |
13316 KB |
Output is correct |
4 |
Correct |
126 ms |
15116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
14152 KB |
Output is correct |
2 |
Correct |
156 ms |
14696 KB |
Output is correct |
3 |
Correct |
90 ms |
14332 KB |
Output is correct |
4 |
Correct |
172 ms |
16060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
658 ms |
37756 KB |
Output is correct |
2 |
Incorrect |
493 ms |
23860 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
688 ms |
34352 KB |
Output is correct |
2 |
Incorrect |
472 ms |
23656 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |