# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
919466 |
2024-01-31T21:50:32 Z |
noyancanturk |
Meteors (POI11_met) |
C++17 |
|
1226 ms |
65536 KB |
#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
const int lim=3e5+100;
#else
const int lim=1e3+100;
#endif
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define pb push_back
const int mod=1e9+7;
using pii=pair<int,int>;
int tree[lim];
struct fenwick{
int n;
fenwick(int n):n(n){
for(int i=0;i<=n;i++)tree[i]=0;
}
void update(int p,int val){
while(p<=n){
tree[p]+=val;
p+=p&-p;
}
}
void update(int l,int r,int val){
update(l,val),update(r+1,-val);
}
int query(int p){
int ans=0;
while(p){
ans+=tree[p];
p-=p&-p;
}
return ans;
}
};
struct bs{
signed l,r;
signed i;
};
inline void solve(){
int n,m;
cin>>n>>m;
vector<signed>v[n+1];
for(int i=1;i<=m;i++){
int tem;
cin>>tem;
v[tem].pb(i);
}
int goal[n+1];
for(int i=1;i<=n;i++){
cin>>goal[i];
}
int k;
cin>>k;
bs all[k+1];
for(int i=1;i<=k;i++){
cin>>all[i].l>>all[i].r>>all[i].i;
}
vector<signed>qq[k+1];
for(int i=1;i<=n;i++){
qq[(1+k)>>1].pb(i);
}
signed l[k+1],r[k+1];
l[(1+k)>>1]=1,r[(1+k)>>1]=k;
signed ans[n+1];
memset(ans,-1,sizeof(ans));
bool ok=1;
while(ok){
ok=0;
fenwick st(m+10);
for(int t=1;t<=k;t++){
if(all[t].l<=all[t].r)st.update(all[t].l,all[t].r,all[t].i);
else {
st.update(all[t].l,m,all[t].i);
st.update(1,all[t].r,all[t].i);
}
while(qq[t].size()){
int now=qq[t].back();
qq[t].pop_back();
//cerr<<now.l<<" "<<now.r<<" "<<now.i<<"\n\n";
int tot=0;
for(int j:v[now]){
tot+=st.query(j);
if(goal[now]<=tot)break;
}
//cerr<<mid<<" "<<tot<<"\n\n";
int mid=(l[t]+r[t])>>1;
if(goal[now]<=tot){
ans[now]=mid;
if(l[t]<=mid-1){
qq[(l[t]+mid-1)>>1].pb(now);
l[(l[t]+mid-1)>>1]=l[t];
r[(l[t]+mid-1)>>1]=mid-1;
ok=1;
}
}else{
if(mid+1<=r[t]){
qq[(mid+1+r[t])>>1].pb(now);
l[(mid+1+r[t])>>1]=mid+1;
r[(mid+1+r[t])>>1]=r[t];
ok=1;
}
}
}
}
}
for(int i=1;i<=n;i++){
if(ans[i]==-1)cout<<"NIE\n";
else cout<<ans[i]<<"\n";
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
#ifdef Local
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#else
#endif
int t=1;
//cin>>t;
while (t--)
{
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
5720 KB |
Output is correct |
2 |
Correct |
78 ms |
8016 KB |
Output is correct |
3 |
Correct |
64 ms |
7476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
6736 KB |
Output is correct |
2 |
Correct |
70 ms |
6992 KB |
Output is correct |
3 |
Correct |
78 ms |
8176 KB |
Output is correct |
4 |
Correct |
19 ms |
4900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
6196 KB |
Output is correct |
2 |
Correct |
61 ms |
8784 KB |
Output is correct |
3 |
Correct |
30 ms |
2648 KB |
Output is correct |
4 |
Correct |
69 ms |
7936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
4952 KB |
Output is correct |
2 |
Correct |
66 ms |
6740 KB |
Output is correct |
3 |
Correct |
47 ms |
5456 KB |
Output is correct |
4 |
Correct |
81 ms |
9300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
504 ms |
31448 KB |
Output is correct |
2 |
Correct |
534 ms |
17028 KB |
Output is correct |
3 |
Correct |
160 ms |
11364 KB |
Output is correct |
4 |
Correct |
1173 ms |
61008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
561 ms |
29920 KB |
Output is correct |
2 |
Correct |
774 ms |
17108 KB |
Output is correct |
3 |
Correct |
148 ms |
9040 KB |
Output is correct |
4 |
Correct |
1226 ms |
65536 KB |
Output is correct |