#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxn=300000;
vector<signed> belong[mxn+10];
signed tar[mxn+10];
signed l[mxn+10],r[mxn+10],mid[mxn+10];
int num[mxn+10];
int tree[mxn+10];
struct node{
signed l1,r1,l2,r2;
int x;
signed time;
} event[mxn+10];
bool cmp(node a,node b){
if (a.time<b.time || (a.time==b.time && a.x>b.x)) return true;
return false;
}
bool finished(int q){
for (int i=1;i<=q;i++) if (l[i]!=r[i]) return 0;
return 1;
}
void add(int x,int num){
if (x>mxn) return;
while (x<=mxn){
tree[x]+=num;
x+=x&(-x);
}
}
int que(int x){
int ans=0;
while (x>0){
ans+=tree[x];
x-=x&(-x);
}
return ans;
}
signed main(){
signed n,m;cin>>n>>m;
for (signed i=1;i<=m;i++){
signed x;cin>>x;
belong[x].push_back(i);
}
for (signed i=1;i<=n;i++){
cin>>tar[i];
}
signed q;cin>>q;
for (signed i=1;i<=n;i++) l[i]=1,r[i]=q+1;
for (signed i=1;i<=q;i++){
signed l,r,x;cin>>l>>r>>x;
if (r<l){
event[i]={l,m,1,r,x,i};
}
else event[i]={l,r,-1,-1,x,i};
}
event[q+1]={1,n,-1,-1,(int)1e9,q+1};
while (!finished(n)){
for (signed i=1;i<=mxn+5;i++){
num[i]=tree[i]=0;
}
for (signed i=1;i<=n;i++) mid[i]=l[i]+(r[i]-l[i])/2;
vector<node> qu;
for (signed i=1;i<=n;i++){
qu.push_back({-1,-1,-1,-1,-i,mid[i]});
}
for (signed i=1;i<=q;i++) qu.push_back({event[i]});
sort(qu.begin(),qu.end(),cmp);
for (auto x:qu){
if (x.x<0){
x.x*=-1;
for (auto a:belong[x.x]){
num[x.x]+=que(a);
}
}
else{
add(x.l1,x.x);add(x.r1+1,-x.x);
if (x.l2>0){
add(x.l2,x.x);add(x.r2+1,-x.x);
}
}
}
for (signed i=1;i<=n;i++){
if (l[i]==r[i]) continue;
if (num[i]>=tar[i]){
r[i]=mid[i];
}
else l[i]=mid[i]+1;
}
}
for (signed i=1;i<=n;i++){
if (l[i]==q+1) cout<<"NIE\n";
else cout<<l[i]<<"\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
18008 KB |
Output is correct |
2 |
Correct |
8 ms |
18012 KB |
Output is correct |
3 |
Correct |
6 ms |
18012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
18012 KB |
Output is correct |
2 |
Correct |
6 ms |
18036 KB |
Output is correct |
3 |
Correct |
7 ms |
18068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
208 ms |
23752 KB |
Output is correct |
2 |
Correct |
452 ms |
26832 KB |
Output is correct |
3 |
Correct |
268 ms |
24620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
289 ms |
24416 KB |
Output is correct |
2 |
Correct |
334 ms |
24016 KB |
Output is correct |
3 |
Correct |
410 ms |
26916 KB |
Output is correct |
4 |
Correct |
71 ms |
20304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
240 ms |
23824 KB |
Output is correct |
2 |
Correct |
407 ms |
27512 KB |
Output is correct |
3 |
Correct |
236 ms |
23288 KB |
Output is correct |
4 |
Correct |
346 ms |
26524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
310 ms |
24024 KB |
Output is correct |
2 |
Correct |
312 ms |
24016 KB |
Output is correct |
3 |
Correct |
235 ms |
23648 KB |
Output is correct |
4 |
Correct |
381 ms |
27384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2547 ms |
65536 KB |
Output is correct |
2 |
Incorrect |
2558 ms |
60688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2475 ms |
65536 KB |
Output is correct |
2 |
Incorrect |
2216 ms |
60340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |