Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define LINT long long int
- using namespace std;
- struct Comp {
- int start_time;
- int end_time;
- int cost;
- Comp(int s, int e, int c) : start_time(s), end_time(e), cost(c){}
- Comp() : start_time(0), end_time(0), cost(0){}
- };
- int main()
- {
- int a;
- cin >> a;
- vector<pair<int, LINT> > s; // cost
- vector<pair<int, LINT> > s1; // time
- vector<Comp> vc(a, *(new Comp()));
- for (auto& x : vc) {
- cin >> x.start_time >> x.end_time >> x.cost;
- }
- sort(vc.begin(), vc.end(), [](Comp& a, Comp& b){return a.start_time < b.start_time;});
- LINT prev = 0;
- for (const auto& x : vc) {
- prev += x.cost;
- s.push_back({x.start_time, prev});
- }
- sort(vc.begin(), vc.end(), [](Comp& a, Comp& b){return a.end_time < b.end_time;});
- prev = 0;
- for (const auto& x : vc) {
- prev += x.end_time - x.start_time;
- s1.push_back({x.end_time, prev});
- }
- int b;
- cin >> b;
- for (int i = 0; i < b; ++i) {
- int a1, a2, a3;
- cin >> a1 >> a2 >> a3;
- if (a3 == 1) {
- auto l = upper_bound(s.begin(), s.end(), pair<int, LINT>({a1, INT64_MIN}));
- auto r = upper_bound(l, s.end(), pair<int, LINT>({a2, INT64_MAX}));
- if (r == s.begin()) {
- cout << 0 << ' ';
- continue;
- }
- if (l == s.begin()) {
- r--;
- cout << r->second << ' ';
- continue;
- }
- l--;
- r--;
- cout << r->second - l->second << ' ';
- } else {
- auto l = upper_bound(s1.begin(), s1.end(), pair<int, LINT>({a1, INT64_MIN}));
- auto r = upper_bound(l, s1.end(), pair<int, LINT>({a2, INT64_MAX}));
- if (r == s1.begin()) {
- cout << 0 << ' ';
- continue;
- }
- if (l == s1.begin()) {
- r--;
- cout << r->second << ' ';
- continue;
- }
- l--;
- r--;
- cout << r->second - l->second << ' ';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement