제출 #1151147

#제출 시각아이디문제언어결과실행 시간메모리
1151147jemin0619Meteors (POI11_met)C++20
100 / 100
1199 ms40732 KiB
#include <bits/stdc++.h> using namespace std; #define fastio cin.tie(NULL)->sync_with_stdio(false) #define ll long long #define pii pair<ll,ll> #define tiii tuple<ll,ll,ll> #define vi vector<ll> #define all(V) V.begin(), V.end() #define xx first #define yy second template <typename T> struct fenwick{ int sz; vector<T> bit; fenwick(int sz):sz(sz){bit.resize(sz+1);} void upd(int i, T val){ for(;i<=sz;i+=i&-i) bit[i] += val; } T sum(int i){ T ret = 0; for(;i;i-=i&-i) ret += bit[i]; return ret; } }; void solve(){ ll N,M; cin>>N>>M; vector<ll> area[N+1]; //area[i] : i번 회원국이 가진 구역들 vector<ll> p(N+1); //p[i] : i번 회원국의 운석 샘플 목표량 for(int i=1; i<=M; i++){ int x; cin>>x; area[x].push_back(i); } for(int i=1; i<=N; i++) cin>>p[i]; int k; cin>>k; vector<tiii> meteor(k); for(int i=0; i<k; i++){ ll l,r,a; cin>>l>>r>>a; meteor[i] = {l,r,a}; } vector<ll> lo(N+1, 0); vector<ll> hi(N+1, k+1); while(true){ bool flag = true; vector<vector<ll>> g(k+3); for(int i=1; i<=N; i++){ if(lo[i]+1 < hi[i]){ g[(lo[i]+hi[i])/2].push_back(i); flag = false; } } if(flag) break; fenwick<ll> fw(M+3); for(int i=0; i<k; i++){ auto[l,r,a] = meteor[i]; if(l<=r) fw.upd(l, a), fw.upd(r+1, -a); else fw.upd(1, a), fw.upd(r+1, -a), fw.upd(l, a), fw.upd(M+1, -a); for(int j : g[i+1]){ ll val = 0; for(int k : area[j]){ val += fw.sum(k); if(val >= p[j]) break; } if(val >= p[j]) hi[j] = i+1; else lo[j] = i+1; } } } for(int i=1; i<=N; i++){ if(hi[i]==k+1) cout<<"NIE\n"; else cout<<hi[i]<<'\n'; } } int main(){ fastio; int tc=1; //cin>>tc; while(tc--) solve(); 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...