Submission #1015551

#TimeUsernameProblemLanguageResultExecution timeMemory
1015551vjudge1Meteors (POI11_met)C++17
74 / 100
890 ms49824 KiB
#include <bits/stdc++.h> #include <fstream> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define endl '\n' #define pb push_back #define mod 1000000007 #define INF 100000000000000000 #define INF2 2000000000 #define fi first #define se second using namespace std; double const EPS = 1e-14; const int P = 1007; typedef long long ll; using namespace __gnu_pbds; typedef long long ll; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key const int N = 3e5 + 4; ll arr[N], tar[N]; int ans[N]; vector<int> mid[N], where[N]; pair<int,int> rang[N]; struct Q { int l, r; ll val; }; Q query[N]; int main() { ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); int n, m; cin >> n >> m; for(int i = 1; i <= m; i++){ cin >> arr[i]; where[arr[i]].push_back(i); } for(int i = 1; i <= n; i++) { cin >> tar[i]; ans[i] = -1; } int k; cin >> k; for(int i = 1; i <= k; i++) { int a, b; ll c; cin >> a >> b >> c; query[i].l = a; query[i].r = b; query[i].val = c; } for(int i = 1; i <= n; i++) { rang[i].fi = 1; rang[i].se = k; } while(true) { ll cal[m+2] = {}; bool ok = false; for(int i = 1; i <= n; i++) { if(rang[i].fi <= rang[i].se) { ll indx = (rang[i].fi+rang[i].se)/2; mid[indx].push_back(i); ok = true; } } if(!ok) break; for(int i = 1; i <= k; i++) { int l = query[i].l, r = query[i].r; ll val = query[i].val; if(l <= r) { for(int j = l; j <= m; j += -j&j) cal[j] += val; for(int j = r+1; j <= m; j += -j&j) cal[j] -= val; } else { for(int j = 1; j <= m; j += -j&j) cal[j] += val; for(int j = r+1; j <= m; j += -j&j) cal[j] -= val; for(int j = l; j <= m; j += -j&j) cal[j] += val; } if(mid[i].size() > 0) { for(auto j : mid[i]) { ll sum = 0; for(auto z : where[j]) { for(int indx = z; indx > 0; indx -= -indx&indx) { sum += cal[indx]; } } if(sum >= tar[j]) { rang[j].se = i-1; ans[j] = i; } else { rang[j].fi = i+1; } } mid[i].clear(); } } } for(int i = 1; i <= n; i++) { if(ans[i] != -1) cout << ans[i] << endl; else cout << "NIE" << endl; } 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...