Submission #799341

#TimeUsernameProblemLanguageResultExecution timeMemory
799341dreamoonMeteors (POI11_met)C++14
74 / 100
606 ms65536 KiB
#include <iostream> #include <vector> #include <algorithm> #define ll long long #define SZ(X) (int)(X.size()) #define MAX 300005 #define pii pair <int,ll> #define ind first #define val second #define INF (ll)(1e18) using namespace std; struct Query{ int le, ri, amo; }; int typeNum, len, queNum; int arr[MAX]; int ans[MAX]; ll need[MAX],pre[MAX]; vector <int> sta[MAX]; // stations of every type vector <Query> allQ; vector <int> allT; int a, b, c; void solve(int le, int ri, vector <int> & type){ // type: station types and how much is needed, pos = le //cout << le << " " << ri << " " << SZ(type) << "\n"; if (type.empty()) return; vector <pii> loc; // considered locations and dif vector <int> tCopy; // copy of type for (int t : type){ pre[t] = need[t]; for (int s : sta[t]) loc.push_back({s, 0}); tCopy.push_back(t); } sort(loc.begin(), loc.end()); if (loc.empty()) return; int mid = le + (ri-le+2)/2; for (int i = le; i < mid; i++){ // set up prefix difference Query q = allQ[i]; int add = q.le, sub = q.ri; if (q.le > q.ri) { // ring-shaped array loc[0].val += q.amo; } auto it = lower_bound(loc.begin(), loc.end(), make_pair(add, -INF)); if (it != loc.end()) it->val += q.amo; it = lower_bound(loc.begin(), loc.end(), make_pair(sub+1, -INF)); if (it != loc.end()) it->val -= q.amo; } ll sum = 0; for (pii l : loc){ // use prefix difference to calculate how much more we need for each type sum += l.val; auto it = lower_bound(tCopy.begin(), tCopy.end(), arr[l.ind]); need[*it] -= sum; //cout << sum << " "; } if (le == ri){ // this is the final step for (int t : tCopy){ if (need[t] <= 0) ans[t] = le+1; } return; } vector <int> typeA, typeB; for (int i = 0; i < SZ(type); i++){ if (need[type[i]] <= 0) { need[type[i]] = pre[type[i]]; typeA.push_back(type[i]); } else typeB.push_back(type[i]); } solve(le, mid-1, typeA); solve(mid, ri, typeB); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> typeNum >> len; for (int i = 1; i <= len; i++) { cin >> arr[i]; sta[arr[i]].push_back(i); } for (int i = 1; i <= typeNum; i++){ cin >> need[i]; allT.push_back(i); } cin >> queNum; for (int i = 0; i < queNum; i++){ cin >> a >> b >> c; allQ.push_back({a, b, c}); } solve(0, queNum-1, allT); for (int i = 1; i <= typeNum; i++){ if (ans[i] == 0) cout << "NIE\n"; else cout << ans[i] << "\n"; } }
#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...