Submission #956105

#TimeUsernameProblemLanguageResultExecution timeMemory
956105RifalMeteors (POI11_met)C++14
100 / 100
1369 ms65536 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 mod 1000000007 #define INF 1000000001 #define INF2 2000000000 ///#define cin fin ///#define cout fout using namespace std; double const EPS = 1e-14; const int P = 1007; typedef long long ll; ///ofstream fout("herding.out"); ///ifstream fin("herding.in"); using namespace __gnu_pbds; 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 Max = 3e5 + 5; vector<int> where[Max], bi[Max]; 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++) { int x; cin >> x; where[x].push_back(i); } ll arr[n+1], ans[n+1]= {}; for(int i = 1; i <= n; i++) cin >> arr[i]; int k; cin >> k; ll qu[k+1][3]; for(int i = 1; i <= k; i++) { cin >> qu[i][0] >> qu[i][1] >> qu[i][2]; } pair<int,int> cur[n+1]; for(int i = 1; i <= n; i++) { cur[i].first = 1; cur[i].second = k; } while(true) { bool check = false; for(int i = 1; i <= n; i++) { if(cur[i].first > cur[i].second) continue; check = true; int mid = (cur[i].first+cur[i].second)/2; bi[mid].push_back(i); } if(!check) break; ll fnwk[m+1] = {}; for(int i = 1; i <= k; i++) { if(qu[i][0] > qu[i][1]) { for(int j = qu[i][0]; j <= m; j += j&-j) { fnwk[j] += qu[i][2]; } for(int j = 1; j <= m; j+= j&-j) { fnwk[j] += qu[i][2]; } for(int j = qu[i][1]+1; j <= m; j+= j&-j) { fnwk[j] -= qu[i][2]; } } else { for(int j = qu[i][0]; j <= m; j+= j&-j) { fnwk[j] += qu[i][2]; } for(int j = qu[i][1]+1; j <= m; j+= j&-j) { fnwk[j] -= qu[i][2]; } } // cout << i << 'i' << endl; for(auto j : bi[i]) { ll sum1 = 0; // cout << j << 'j' << endl; for(auto z : where[j]) { // cout << z << 'z' << endl; int pos = z; ll sum2 = 0; for(int b = pos; b > 0; b -= b&-b) { sum2 += fnwk[b]; } // cout << sum2 << ' ' << "sum2" << endl; sum1 += sum2; if(sum1 >= arr[j]) { // cout << 'Y' << endl; break; } } // cout << sum1<< ' ' << "sum" << endl; if(sum1 >= arr[j]) { cur[j].second = i-1; ans[j] = i; } else { cur[j].first = i+1; } } bi[i].clear(); } } for(int i = 1; i <= n; i++) { if(ans[i] == 0) cout << "NIE" << endl; else cout << ans[i] << 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...