Submission #55179

# Submission time Handle Problem Language Result Execution time Memory
55179 2018-07-06T08:52:12 Z paulica Printed Circuit Board (CEOI12_circuit) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define _ << " _ " <<#include <bits/stdc++.h>
using namespace std;

#define _ << " _ " <<
#define TRACE(x) cout << #x << " = " << x << endl

#define fi first
#define se second
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

const int MaxN = 2e5 + 10;

int n, x[MaxN], y[MaxN];
pair<int, int> line[MaxN];

ll ccw(int i, int j, int k) {
    return (ll)x[i] * (y[j] - y[k]) +
           (ll)x[j] * (y[k] - y[i]) +
           (ll)x[k] * (y[i] - y[j]);
}

ll ccw0(int i, int j) {
    return (ll)x[i] * y[j] - (ll)x[j] * y[i];
}

ll dist(int i) {
    return (ll)x[i] * x[i] + (ll)y[i] * y[i];
}

bool equ(int i, int j) {
    return (ll)y[i] * x[j] == (ll)y[j] * x[i];
}

bool pointCmp(int i, int j) {
    if (equ(i, j)) return dist(i) < dist(j);
    return (ll)y[i] * x[j] < (ll)y[j] * x[i];
}

bool eventCmp(pair<pii, int>& a, pair<pii, int>& b) {
    if (equ(a.fi.fi, b.fi.fi) && a.se != b.se) return a.se < b.se;
    return pointCmp(a.fi.fi, b.fi.fi);
}

bool above(int i, int j) {
    int a = line[j].fi, b = line[j].se;

    if (ccw0(a, b) == 0) return x[i] >= max(x[a], x[b]);
    else if (i == a || i == b) return false;
    else return (ccw0(a, i) < 0) || (ccw(a, b, i) < 0) || (ccw0(i, b) < 0);
}

struct lineCmp {
    bool operator()(int i, int j) {
        if (i == j) return false;

        int a1 = line[i].fi, b1 = line[i].se;
        int a2 = line[j].fi, b2 = line[j].se;

        if (pointCmp(a1, a2) && pointCmp(a2, b1))
            return above(a2, i);
        else if (pointCmp(a1, b2) && pointCmp(b2, b1))
            return above(b2, i);
        else if (pointCmp(a2, a1) && pointCmp(a1, b2))
            return !above(a1, j);
        else if (pointCmp(a2, b1) && pointCmp(b1, b2))
            return !above(b1, j);
        else if (b1 == a2)
            return false;
        else if (b2 == a1)
           return true;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

    vector<pair<pii, int>> events;

    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        events.push_back({{i, i}, 1});
    }
    
    for (int i = 0; i < n; i++) {
        if (i == n - 1) line[i] = {i, 0};
        else line[i] = {i, i + 1};
        
        if (pointCmp(line[i].se, line[i].fi))
            swap(line[i].fi, line[i].se);

        events.push_back({{line[i].fi, i}, 0});
        events.push_back({{line[i].se, i}, 2});
    }

    sort(events.begin(), events.end(), eventCmp);

    multiset<int, lineCmp> lines;

    vector<int> sol;

    for (auto ev : events) {
        if (ev.se == 0) {
            lines.insert(ev.fi.se);
        } else if (ev.se == 1) {
            int i = ev.fi.se;
            int j = *lines.begin();
            if (!above(i, j)) sol.push_back(i);
        } else {
            lines.erase(ev.fi.se);
        }
    }

    sort(sol.begin(), sol.end());

    cout << sol.size() << "\n";
    for (int i : sol) cout << i + 1 << " ";

    return 0;
}


#define TRACE(x) cout << #x << " = " << x << endl

#define fi first
#define se second
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

const int MaxN = 1e5 + 10;

int n, x[MaxN], y[MaxN];
pair<int, int> line[MaxN];

ll ccw(int i, int j, int k) {
    return (ll)x[i] * (y[j] - y[k]) +
           (ll)x[j] * (y[k] - y[i]) +
           (ll)x[k] * (y[i] - y[j]);
}

ll ccw0(int i, int j) {
    return (ll)x[i] * y[j] - (ll)x[j] * y[i];
}

ll dist(int i) {
    return (ll)x[i] * x[i] + (ll)y[i] * y[i];
}

bool equ(int i, int j) {
    return (ll)y[i] * x[j] == (ll)y[j] * x[i];
}

bool pointCmp(int i, int j) {
    if (equ(i, j)) return dist(i) < dist(j);
    return (ll)y[i] * x[j] < (ll)y[j] * x[i];
}

bool eventCmp(pair<pii, int>& a, pair<pii, int>& b) {
    if (equ(a.fi.fi, b.fi.fi) && a.se != b.se) return a.se < b.se;
    return pointCmp(a.fi.fi, b.fi.fi);
}

void printLine(int i) {cout << line[i].fi + 1 << "-" << line[i].se + 1 << " ";}
/*
ld intersec(int i, int j) {
    int a = line[j].fi, b = line[j].se;

    if (x[a] == x[b]) return x[a];

    ld k1 = (ld)y[i] / x[i];
    ld k2 = (ld)(y[a] - y[b]) / (x[a] - x[b]);
    ld l = (ld)((ll)x[a] * y[b] - (ll)x[b] * y[a]) / (x[a] - x[b]);

    if (k1 - k2 == 0) return min(x[a], x[b]);

    *
    cout << "intersec " << i + 1 << " ";
    printLine(j);
    cout << l / (k1 -k2) << endl;

    
    return l / (k1 - k2);
}*/

bool above(int i, int j) {
    int a = line[j].fi, b = line[j].se;
    bool ret = false;
    //cout << x[a] << "," << y[a] << " " << x[b] << "," << y[b] << " " << x[i] << "," << y[i] << " " << ccw(a, b, 0) << endl; 
    if (ccw0(a, b) == 0) ret = x[i] >= max(x[a], x[b]);
    else if (i == a || i == b) ret = false;
    else ret = (ccw0(a, i) < 0) || (ccw(a, b, i) < 0) || (ccw0(i, b) < 0);
    //cout << "above " << i + 1 << " ", printLine(j), cout << " " << ret << endl;
    return ret;
}

int mod(int i) {
    if (i >= n) return i - n;
    return i;
}

struct lineCmp {
    bool operator()(int i, int j) {
        if (i == j) return false;

        bool ret = false;

        int a1 = line[i].fi, b1 = line[i].se;
        int a2 = line[j].fi, b2 = line[j].se;

        int ty = 0;
        /* else*/ if (pointCmp(a1, a2) && pointCmp(a2, b1))
            ret = above(a2, i), ty = 1;
        else if (pointCmp(a1, b2) && pointCmp(b2, b1))
            ret = above(b2, i), ty = 2;
        else if (pointCmp(a2, a1) && pointCmp(a1, b2))
            ret = !above(a1, j), ty = 3;
        else if (pointCmp(a2, b1) && pointCmp(b1, b2))
            ret = !above(b1, j), ty = 4;
        else if (b1 == a2)
            ret = false, ty = 5;
        else if (b2 == a1)
           ret = true, ty = 6;
        //else cout << "kurac", printLine(i), printLine(j), cout << endl;


        /*
        cout << "cmp ";
        printLine(i);
        printLine(j);
        cout << ret << " " << ty << endl;
        //cin.get();
        /**/
        return ret;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

    vector<pair<pii, int>> events;

    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        events.push_back({{i, i}, 1});
    }
    
    for (int i = 0; i < n; i++) {
        if (i == n - 1) line[i] = {i, 0};
        else line[i] = {i, i + 1};
        
        if (pointCmp(line[i].se, line[i].fi))
            swap(line[i].fi, line[i].se);

        events.push_back({{line[i].fi, i}, 0});
        events.push_back({{line[i].se, i}, 2});
    }

    sort(events.begin(), events.end(), eventCmp);

    multiset<int, lineCmp> lines;

    vector<int> sol;

    for (auto ev : events) {
        if (ev.se == 0) {
            lines.insert(ev.fi.se);
            //int l = ev.fi.se;
            //cout << "+ ";
            //printLine(l);
            //cout << endl;
        } else if (ev.se == 1) {
            int i = ev.fi.se;
//            cout << endl;
         //   TRACE(i + 1);
          //  for (int l : lines) cout << line[l].fi + 1 << "-" << line[l].se + 1  << " "; cout << endl;
            int j = *lines.begin();
      //      cout << line[j].fi + 1 << "-" << line[j].se + 1 << endl;

 //           if (intersec(i, j) >= x[i]) 
            if (!above(i, j)) sol.push_back(i);
          //  if (!above(i, j)) cout << "yes\n";
        //    cout << endl;
        } else {
   //         cout << "!" << (lines.find(ev.fi.se) != lines.end()) << "!\n";
            //if (lines.find(ev.fi.se) == lines.end()) cout << "joj ", printLine(ev.fi.se), cout << endl;
      //      cout << lines.size() << " -> ";
            lines.erase(ev.fi.se);
        //    cout << lines.size() << "  ";
            //cout << "- ";
           // printLine(ev.fi.se);
           // cout << "   " << ev.fi.se << endl;
        }
    }

    sort(sol.begin(), sol.end());

    cout << sol.size() << "\n";
    for (int i : sol) cout << i + 1 << " ";
    
/*
    cout << "\nbrut:\n";
    for (int i = 0; i < n; i++) {
        bool ok = true;
        for (int j = 0; j < n; j++)
            if (pointCmp(line[j].fi, i) && pointCmp(i, line[j].se) && above(i, j))
                    ok = false;
        if (ok) cout << i + 1 << " ";
    }
    */

    return 0;
}

Compilation message

circuit.cpp:7:0: warning: "_" redefined
 #define _ << " _ " <<
 
circuit.cpp:4:0: note: this is the location of the previous definition
 #define _ << " _ " <<#include <bits/stdc++.h>
 
circuit.cpp:240:9: warning: "/*" within comment [-Wcomment]
         /**/
          
circuit.cpp:138:11: error: redefinition of 'const int MaxN'
 const int MaxN = 1e5 + 10;
           ^~~~
circuit.cpp:16:11: note: 'const int MaxN' previously defined here
 const int MaxN = 2e5 + 10;
           ^~~~
circuit.cpp:140:5: error: redefinition of 'int n'
 int n, x[MaxN], y[MaxN];
     ^
circuit.cpp:18:5: note: 'int n' previously declared here
 int n, x[MaxN], y[MaxN];
     ^
circuit.cpp:140:14: error: redefinition of 'int x [200010]'
 int n, x[MaxN], y[MaxN];
              ^
circuit.cpp:18:8: note: 'int x [200010]' previously declared here
 int n, x[MaxN], y[MaxN];
        ^
circuit.cpp:140:23: error: redefinition of 'int y [200010]'
 int n, x[MaxN], y[MaxN];
                       ^
circuit.cpp:18:17: note: 'int y [200010]' previously declared here
 int n, x[MaxN], y[MaxN];
                 ^
circuit.cpp:141:25: error: redefinition of 'std::pair<int, int> line [200010]'
 pair<int, int> line[MaxN];
                         ^
circuit.cpp:19:16: note: 'std::pair<int, int> line [200010]' previously defined here
 pair<int, int> line[MaxN];
                ^~~~
circuit.cpp: In function 'll ccw(int, int, int)':
circuit.cpp:143:4: error: redefinition of 'll ccw(int, int, int)'
 ll ccw(int i, int j, int k) {
    ^~~
circuit.cpp:21:4: note: 'll ccw(int, int, int)' previously defined here
 ll ccw(int i, int j, int k) {
    ^~~
circuit.cpp: In function 'll ccw0(int, int)':
circuit.cpp:149:4: error: redefinition of 'll ccw0(int, int)'
 ll ccw0(int i, int j) {
    ^~~~
circuit.cpp:27:4: note: 'll ccw0(int, int)' previously defined here
 ll ccw0(int i, int j) {
    ^~~~
circuit.cpp: In function 'll dist(int)':
circuit.cpp:153:4: error: redefinition of 'll dist(int)'
 ll dist(int i) {
    ^~~~
circuit.cpp:31:4: note: 'll dist(int)' previously defined here
 ll dist(int i) {
    ^~~~
circuit.cpp: In function 'bool equ(int, int)':
circuit.cpp:157:6: error: redefinition of 'bool equ(int, int)'
 bool equ(int i, int j) {
      ^~~
circuit.cpp:35:6: note: 'bool equ(int, int)' previously defined here
 bool equ(int i, int j) {
      ^~~
circuit.cpp: In function 'bool pointCmp(int, int)':
circuit.cpp:161:6: error: redefinition of 'bool pointCmp(int, int)'
 bool pointCmp(int i, int j) {
      ^~~~~~~~
circuit.cpp:39:6: note: 'bool pointCmp(int, int)' previously defined here
 bool pointCmp(int i, int j) {
      ^~~~~~~~
circuit.cpp: In function 'bool eventCmp(std::pair<std::pair<int, int>, int>&, std::pair<std::pair<int, int>, int>&)':
circuit.cpp:166:6: error: redefinition of 'bool eventCmp(std::pair<std::pair<int, int>, int>&, std::pair<std::pair<int, int>, int>&)'
 bool eventCmp(pair<pii, int>& a, pair<pii, int>& b) {
      ^~~~~~~~
circuit.cpp:44:6: note: 'bool eventCmp(std::pair<std::pair<int, int>, int>&, std::pair<std::pair<int, int>, int>&)' previously defined here
 bool eventCmp(pair<pii, int>& a, pair<pii, int>& b) {
      ^~~~~~~~
circuit.cpp: In function 'bool above(int, int)':
circuit.cpp:193:6: error: redefinition of 'bool above(int, int)'
 bool above(int i, int j) {
      ^~~~~
circuit.cpp:49:6: note: 'bool above(int, int)' previously defined here
 bool above(int i, int j) {
      ^~~~~
circuit.cpp: At global scope:
circuit.cpp:209:8: error: redefinition of 'struct lineCmp'
 struct lineCmp {
        ^~~~~~~
circuit.cpp:57:8: note: previous definition of 'struct lineCmp'
 struct lineCmp {
        ^~~~~~~
circuit.cpp: In function 'int main()':
circuit.cpp:245:5: error: redefinition of 'int main()'
 int main() {
     ^~~~
circuit.cpp:79:5: note: 'int main()' previously defined here
 int main() {
     ^~~~
circuit.cpp: In member function 'bool lineCmp::operator()(int, int)':
circuit.cpp:76:5: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^