ohwhatalovelyday

Untitled

Oct 6th, 2021
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define FASTER() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  4. #define ff first
  5. #define ss second
  6. #define pb push_back
  7. #define all(a) a.begin(), a.end()
  8. #define dbg(x) cerr<<" "<<#x<<" "<<x<<endl
  9.  
  10. typedef long long ll;
  11.  
  12. using namespace std;
  13.  
  14. struct line {
  15.     int a, b, c;
  16. //    ll add;
  17.  
  18.     bool operator == (const line &l) {
  19.         if(a != l.a || b != l.b || c != l.c) {
  20.             return false;
  21.         }
  22.         return true;
  23.     }
  24. };
  25.  
  26. struct compLine {
  27.     bool operator() (const line &x, const line &y) const {
  28.         if(x.a == y.a && x.b == y.b) return x.c < y.c;
  29.         if(x.a == y.a) return x.b < y.b;
  30.         return x.a < y.a;
  31.     }
  32. };
  33.  
  34. int main() {
  35.     FASTER();
  36.     int n;
  37.     cin >> n;
  38.     ll sum = 0;
  39.     map <pair <int, int>, ll> cnt;
  40.     set <line, compLine> is;
  41.  
  42.     for(int i = 0; i < n; i++) {
  43.         int t, a, b, c;
  44.         cin >> t >> a >> b >> c;
  45.         int t1 = a, t2 = b;
  46.  
  47.         if (t2 < 0) {
  48.             t1 *= -1, t2 *= -1;
  49.         } else if (t2 == 0 && t1 < 0) {
  50.             t1 *= -1;
  51.         }
  52.         int d = __gcd(t1, t2);
  53.         if(d != 0) t1 /= d, t2 /= d;
  54.  
  55.         if (c < 0) {
  56.             a *= -1, b *= -1, c *= -1;
  57.         } else if (c == 0 && b < 0) {
  58.             a *= -1;
  59.             b *= -1;
  60.         }
  61.         int g = __gcd(a, b);
  62.         g = __gcd(g, c);
  63.         if(g != 0) {
  64.             a /= g, b /= g, c /= g;
  65.         }
  66.         line tmp = {a, b, c};
  67.  
  68.         if (t == 1) {
  69.             ll add;
  70.             cin >> add;
  71.             cnt[{t1, t2}] += add;
  72.             is.insert(tmp);
  73.             sum += add;
  74.         }
  75.         if (t == 2) {
  76.             auto it = is.find(tmp);
  77.             if(it != is.end()) { //если совпадает
  78.                 cout << "inf\n";
  79.                 continue;
  80.             }
  81.             ll ans = sum;
  82.             if (cnt.count({t1, t2}) != 0) { //вычитаем все параллельные
  83.                 ans -= cnt[{t1, t2}];
  84.             }
  85.             cout << ans << '\n';
  86.         }
  87.     }
  88. }
  89.  
Advertisement
Add Comment
Please, Sign In to add comment