Submission #1048315

#TimeUsernameProblemLanguageResultExecution timeMemory
1048315fgbdvcsMeteors (POI11_met)C++14
100 / 100
1216 ms39232 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define ll unsigned long long #define ld long double #define pb push_back #define pf push_front int const maxn = 3e5+7; const ll INF = LLONG_MAX; int n , m , q; int x[maxn] ; int l[maxn] , r[maxn]; int le[maxn] , ri[maxn]; ll v[maxn] , a[maxn]; vector<int> adj[maxn]; vector<int> stage , temp; struct Fw { ll bit[maxn]; Fw() { memset(bit , 0 , sizeof(bit)); } void Clear() { memset(bit , 0 , sizeof(bit)); } void Upd(int u , ll v) { int idx = u; while(idx <= m){ bit[idx] += v; idx += (idx & (- idx)); } } ll Get(int u) { ll re = 0; int idx = u; while(idx){ re += bit[idx]; idx -= (idx & (- idx)); } return re; } }; Fw Fen; void Update(int pos) { Fen.Upd(l[pos] , v[pos]); Fen.Upd(r[pos] + 1 , - v[pos]); if(l[pos] > r[pos]){ Fen.Upd(1 , v[pos]); } } ll Get_sum(int pos) { ll re = 0; for(auto u : adj[pos]){ re += Fen.Get(u); } return re; } void Input() { cin >> n >> m; for(int i = 1 ; i <= m ; i ++){ cin >> x[i]; adj[x[i]].pb(i); } for(int i = 1 ; i <= n ; i ++){ cin >> a[i]; } cin >> q; for(int i = 1 ; i <= q ; i ++){ cin >> l[i] >> r[i] >> v[i]; } } bool cmp(int x , int y) { return (le[x] + ri[x]) / 2 < (le[y] + ri[y]) / 2; } void Solve() { for(int i = 1 ; i <= n ; i ++){ stage.pb(i); le[i] = 1; ri[i] = q; } while(stage.size() != 0){ sort(stage.begin() , stage.end() , cmp); int run = 1; for(auto u : stage){ int mid = (le[u] + ri[u]) / 2; while(run <= mid){ Update(run); run ++; } ll s = Get_sum(u); if(s < a[u]) le[u] = mid + 1; else ri[u] = mid - 1; if(le[u] <= ri[u]) temp.pb(u); } // cout << "Check " << "\n"; // for(int i = 1 ; i <= n ; i ++){ // cout << le[i] << " " << ri[i] << "\n"; // } swap(stage , temp); temp.clear(); Fen.Clear(); } for(int i = 1 ; i <= n ; i ++){ // cout << "le " << le[i] << "\n"; le[i] > q ? cout << "NIE" : cout << le[i]; cout << "\n"; } } int main() { // freopen(".INP","r",stdin); // freopen(".OUT","w",stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr); int tt = 1; //cin >> tt; while(tt--){ Input(); Solve(); } }
#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...