#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=3e5+5;
const ll inf=2e18;
ll n,m,a[maxN+1],k,ans[maxN+1];
vector<ll> v[maxN+1],pos[maxN+1];
struct query
{
ll l,r;
ll x;
}q[maxN+1];
struct met
{
ll l,r,mid,b;
}p[maxN+1];
struct fenwick
{
ll bit[maxN+1];
void clr()
{
memset(bit,0,sizeof(bit));
}
void update(ll u,ll val)
{
for(ll i=u;i<=m;i+=(i&(-i)))
{
bit[i]+=val;
}
}
void update_range(ll l,ll r,ll val)
{
update(l,val);
update(r+1,-val);
}
ll get(ll u)
{
ll ans=0;
for(ll i=u;i>0;i-=(i&(-i)))
{
ans+=bit[i];
}
return ans;
}
}f;
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>a[i];
assert(a[i]<=maxN);
pos[a[i]].push_back(i);
}
for(int i=1;i<=n;i++)
{
cin>>p[i].b;
}
cin>>k;
for(int i=1;i<=k;i++)
{
cin>>q[i].l>>q[i].r>>q[i].x;
assert(q[i].l<=maxN);
assert(q[i].r<=maxN);
}
for(int i=1;i<=n;i++)
{
p[i].l=1;
p[i].r=k;
ans[i]=-1;
}
while(1)
{
bool ok=false;
for(int i=1;i<=n;i++)
{
if(p[i].l<=p[i].r)
{
p[i].mid=(p[i].l+p[i].r)/2;
ok=true;
assert(p[i].mid>=0&&p[i].mid<=maxN);
v[p[i].mid].push_back(i);
}
}
f.clr();
if(!ok)
{
break;
}
for(int i=1;i<=k;i++)
{
if(q[i].l>q[i].r)
{
f.update_range(q[i].l,m,q[i].x);
f.update_range(1,q[i].r,q[i].x);
}
else f.update_range(q[i].l,q[i].r,q[i].x);
for(auto j:v[i])
{
ll res=0;
for(auto id:pos[j])
{
res+=f.get(id);
}
if(res>=p[j].b)
{
ans[j]=p[j].mid;
p[j].r=p[j].mid-1;
}
else p[j].l=p[j].mid+1;
}
v[i].clear();
}
}
for(int i=1;i<=n;i++)
{
assert(p[i].l>p[i].r);
if(p[i].l>k)
{
cout<<"NIE";
}
else
{
assert(ans[i]>=1&&ans[i]<=k);
cout<<p[i].l;
}
cout<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
21080 KB |
Output is correct |
2 |
Correct |
4 ms |
21084 KB |
Output is correct |
3 |
Correct |
4 ms |
21060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
21080 KB |
Output is correct |
2 |
Correct |
4 ms |
21084 KB |
Output is correct |
3 |
Correct |
4 ms |
21084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
23636 KB |
Output is correct |
2 |
Correct |
77 ms |
26552 KB |
Output is correct |
3 |
Correct |
58 ms |
25528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
24916 KB |
Output is correct |
2 |
Correct |
64 ms |
24784 KB |
Output is correct |
3 |
Correct |
85 ms |
26912 KB |
Output is correct |
4 |
Correct |
18 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
24144 KB |
Output is correct |
2 |
Correct |
55 ms |
27152 KB |
Output is correct |
3 |
Correct |
35 ms |
22364 KB |
Output is correct |
4 |
Correct |
58 ms |
26108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
76 ms |
22740 KB |
Output is correct |
2 |
Correct |
83 ms |
24824 KB |
Output is correct |
3 |
Correct |
41 ms |
23128 KB |
Output is correct |
4 |
Correct |
94 ms |
28116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
801 ms |
51992 KB |
Output is correct |
2 |
Incorrect |
553 ms |
30808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
860 ms |
49696 KB |
Output is correct |
2 |
Incorrect |
652 ms |
28856 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |