Submission #975009

#TimeUsernameProblemLanguageResultExecution timeMemory
975009NinedesuMeteors (POI11_met)C++14
74 / 100
909 ms28512 KiB
#include<bits/stdc++.h> #define ll long long #define pii pair<int,int> #define piii pair<ll,pii> using namespace std; const int N=3e5+1; int m,n,q; int arr[N],want[N],l[N],r[N]; piii up[N]; bitset<N>can,vis; vector<int>own[N]; priority_queue<pii,vector<pii>,greater<pii>>pq; class fenwick{ public: ll tree[N]; void reset(){ for(int i=1; i<=n; i++)tree[i]=0; } void update(int idx,ll val){ while(idx<=n){ tree[idx]+=val; idx+=(idx&-idx); } } ll query(int idx){ ll sum=0; while(idx){ sum+=tree[idx]; idx-=(idx&-idx); } return sum; } }fw; int main(){ ios_base::sync_with_stdio(0),cin.tie(0); cin >> m >> n; for(int i=1; i<=n; i++){ cin >> arr[i]; own[arr[i]].push_back(i); } for(int i=1; i<=m; i++){ cin >> want[i]; } cin >> q; for(int i=1; i<=m; i++){ l[i]=1; r[i]=q; } for(int i=1; i<=q; i++){ cin >> up[i].second.first >> up[i].second.second >> up[i].first; } bool chk=true; while(chk){ chk=false; int mxmid=0; for(int i=1; i<=m; i++){ if(vis[i])continue; chk=true; int mid=(l[i]+r[i])>>1; mxmid=max(mxmid,mid); pq.push({mid,i}); } for(int i=1; i<=mxmid; i++){ ll z=up[i].first; int x=up[i].second.first; int y=up[i].second.second; if(x<=y){ fw.update(x,z); if(y<n)fw.update(y+1,-z); } else{ fw.update(x,z); fw.update(1,z); fw.update(y+1,-z); } while(!pq.empty()){ int mid=pq.top().first; int idx=pq.top().second; if(mid!=i)break; pq.pop(); ll sum=0; for(int j:own[idx]){ sum+=fw.query(j); } if(sum>=want[idx])can[idx]=true; if(l[idx]==r[idx])vis[idx]=true; if(sum<want[idx])l[idx]=mid+1; else r[idx]=mid; } } fw.reset(); } for(int i=1; i<=m; i++){ if(can[i])cout << l[i] << '\n'; else cout << "NIE\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...