Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream in("lasere.in");
- ofstream out("lasere.out");
- #define N (int)1e6
- #define MAX (int)1e9
- map<int, int> nivel;
- vector<tuple<int, int, int>>ordine;
- struct segment {
- int x1, y1, x2, y2;
- }V[N];
- int AI[4 * N];
- int query(int a, int b, int n) {
- a += n; b += n;
- int s = 0;
- while (a <= b) {
- if (a % 2 == 1) s += AI[a++];
- if (b % 2 == 0) s += AI[b--];
- a /= 2; b /= 2;
- }
- return s;
- }
- void update(int k, int x, int n) {
- k += n;
- AI[k] += x;
- for (k /= 2; k >= 1; k /= 2) {
- AI[k] = AI[2 * k] + AI[2 * k + 1];
- }
- }
- int main()
- {
- int n;
- int tip, a, b;
- int x1, x2, y1, y2;
- in >> n;
- for (int i = 0; i < n; i++) {
- in >> tip >> x1 >> a >> b;
- if (tip == 1)
- {
- x2 = x1 + a;
- y1 = y2 = b;
- nivel[y1] = 0;
- ordine.push_back(make_tuple( x1, 0, i ));
- ordine.push_back(make_tuple( x2, 2, i ));
- }
- else
- {
- x2 = x1;
- y1 = a;
- y2 = b;
- nivel[y1] = 0;
- nivel[y2] = 0;
- ordine.push_back(make_tuple( x1, 1, i ));
- }
- V[i].x1 = x1; V[i].y1 = y1;
- V[i].x2 = x2; V[i].y2 = y2;
- }
- int i = 0;
- for (map<int, int>::iterator it = nivel.begin(); it != nivel.end(); it++)
- it->second = i++ + 1;
- sort(ordine.begin(), ordine.end());
- long long suma = 0;
- int s = 0;
- int Maxim = nivel.size();
- for (auto t : ordine) //baleierea
- switch (get<1>(t))
- {
- case 0: //actualizare - intrare
- update(nivel[V[get<2>(t)].y1], 1, Maxim);
- break;
- case 1: //interogare
- s = query(nivel[V[get<2>(t)].y1], nivel[V[get<2>(t)].y2], Maxim);
- out << s << endl;
- suma += s;
- break;
- case 2: //actualizare - iesire
- update(nivel[V[get<2>(t)].y1], -1, Maxim);
- break;
- }
- out << suma;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement