Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define FASTER() ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
- #define ff first
- #define ss second
- #define pb push_back
- #define all(a) a.begin(), a.end()
- #define dbg(x) cerr<<" "<<#x<<" "<<x<<endl
- typedef long long ll;
- using namespace std;
- struct line {
- int a, b, c;
- // ll add;
- bool operator == (const line &l) {
- if(a != l.a || b != l.b || c != l.c) {
- return false;
- }
- return true;
- }
- };
- struct compLine {
- bool operator() (const line &x, const line &y) const {
- if(x.a == y.a && x.b == y.b) return x.c < y.c;
- if(x.a == y.a) return x.b < y.b;
- return x.a < y.a;
- }
- };
- int main() {
- FASTER();
- int n;
- cin >> n;
- ll sum = 0;
- map <pair <int, int>, ll> cnt;
- set <line, compLine> is;
- for(int i = 0; i < n; i++) {
- int t, a, b, c;
- cin >> t >> a >> b >> c;
- int t1 = a, t2 = b;
- if (t2 < 0) {
- t1 *= -1, t2 *= -1;
- } else if (t2 == 0 && t1 < 0) {
- t1 *= -1;
- }
- int d = __gcd(t1, t2);
- if(d != 0) t1 /= d, t2 /= d;
- if (c < 0) {
- a *= -1, b *= -1, c *= -1;
- } else if (c == 0 && b < 0) {
- a *= -1;
- b *= -1;
- }
- int g = __gcd(a, b);
- g = __gcd(g, c);
- if(g != 0) {
- a /= g, b /= g, c /= g;
- }
- line tmp = {a, b, c};
- if (t == 1) {
- ll add;
- cin >> add;
- cnt[{t1, t2}] += add;
- is.insert(tmp);
- sum += add;
- }
- if (t == 2) {
- auto it = is.find(tmp);
- if(it != is.end()) { //если совпадает
- cout << "inf\n";
- continue;
- }
- ll ans = sum;
- if (cnt.count({t1, t2}) != 0) { //вычитаем все параллельные
- ans -= cnt[{t1, t2}];
- }
- cout << ans << '\n';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment