Submission #82046

# Submission time Handle Problem Language Result Execution time Memory
82046 2018-10-28T15:30:43 Z duality Printed Circuit Board (CEOI12_circuit) C++11
75 / 100
100 ms 12912 KB
#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#pragma GCC optimize("Ofast")

int x[100000],y[100000],pos[100000],small[100000];
vector<double> sorted;
pair<pii,pii> tree[1 << 18],lazy[1 << 18];
double value(pair<pii,pii> &p,double a) {
    double d1 = (p.first.first+p.first.second*a);
    double c1 = (p.first.second-p.first.first*a);
    double d2 = (p.second.first+p.second.second*a);
    double c2 = (p.second.second-p.second.first*a);
    return (-c2*d1+c1*d2)/(c1-c2);
}
int comp(pair<pii,pii> &a,pair<pii,pii> &b,int s,int e) {
    if (a.first.first == -1) return 0;
    else if (b.first.first == -1) return 1;
    double m = (sorted[s]+sorted[e+1])/2;
    return value(a,m) < value(b,m);
}
int prop(int s,int e,int i) {
    if (comp(lazy[i],tree[i],s,e)) tree[i] = lazy[i];
    if (s != e) {
        int mid = (s+e) / 2;
        if (comp(lazy[i],lazy[2*i+1],s,mid)) lazy[2*i+1] = lazy[i];
        if (comp(lazy[i],lazy[2*i+2],mid+1,e)) lazy[2*i+2] = lazy[i];
    }
    lazy[i].first.first = -1;
    return 0;
}
int update(int s,int e,int as,int ae,int i,pair<pii,pii> &p) {
    prop(s,e,i);
    if ((s > ae) || (e < as)) return 0;
    else if ((s >= as) && (e <= ae)) {
        lazy[i] = p;
        return 0;
    }

    int mid = (s+e) / 2;
    update(s,mid,as,ae,2*i+1,p),update(mid+1,e,as,ae,2*i+2,p);
    return 0;
}
pair<pii,pii> ans[100000];
int query(int s,int e,int i) {
    prop(s,e,i);
    if (s == e) {
        ans[s] = tree[i];
        return 0;
    }

    int mid = (s+e) / 2;
    query(s,mid,2*i+1),query(mid+1,e,2*i+2);
    return 0;
}
vi sol;
int main() {
    int i;
    int N;
    scanf("%d",&N);
    for (i = 0; i < N; i++) {
        scanf("%d %d",&x[i],&y[i]);
        sorted.pb((double) y[i]/x[i]);
    }
    sort(sorted.begin(),sorted.end());
    sorted.resize(unique(sorted.begin(),sorted.end())-sorted.begin());

    fill(tree,tree+(1 << 18),mp(mp(-1,-1),mp(-1,-1)));
    fill(lazy,lazy+(1 << 18),mp(mp(-1,-1),mp(-1,-1)));
    fill(small,small+sorted.size(),-1);
    for (i = 0; i < N; i++) pos[i] = lower_bound(sorted.begin(),sorted.end(),(double) y[i]/x[i])-sorted.begin();
    for (i = 0; i < N; i++) {
        int p = pos[i],q = pos[(i+1) % N];
        pair<pii,pii> e = mp(mp(x[i],y[i]),mp(x[(i+1) % N],y[(i+1) % N]));
        update(0,sorted.size()-2,min(p,q),max(p,q)-1,0,e);
        if ((small[p] == -1) || (mp(x[i],y[i]) < mp(x[small[p]],y[small[p]]))) small[p] = i;
    }
    query(0,sorted.size()-2,0);
    for (i = 0; i < N; i++) {
        int p = pos[i];
        int l = (p == 0) ? 1:((ans[p-1].first == mp(x[i],y[i])) || (ans[p-1].second == mp(x[i],y[i])));
        int r = (p == sorted.size()-1) ? 1:((ans[p].first == mp(x[i],y[i])) || (ans[p].second == mp(x[i],y[i])));
        if (l && r) sol.pb(i);
        else if ((l || r) && (small[p] == i)) sol.pb(i);
    }
    printf("%d\n",sol.size());
    for (i = 0; i < sol.size(); i++) printf("%d ",sol[i]+1);
    printf("\n");

    return 0;
}

Compilation message

circuit.cpp: In function 'int main()':
circuit.cpp:135:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         int r = (p == sorted.size()-1) ? 1:((ans[p].first == mp(x[i],y[i])) || (ans[p].second == mp(x[i],y[i])));
                  ~~^~~~~~~~~~~~~~~~~~
circuit.cpp:139:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",sol.size());
                   ~~~~~~~~~~^
circuit.cpp:140:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < sol.size(); i++) printf("%d ",sol[i]+1);
                 ~~^~~~~~~~~~~~
circuit.cpp:113:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
circuit.cpp:115:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&x[i],&y[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8568 KB Output is correct
2 Correct 9 ms 8700 KB Output is correct
3 Correct 10 ms 8888 KB Output is correct
4 Correct 11 ms 8920 KB Output is correct
5 Correct 26 ms 9336 KB Output is correct
6 Correct 28 ms 9336 KB Output is correct
7 Correct 50 ms 9632 KB Output is correct
8 Correct 23 ms 9632 KB Output is correct
9 Correct 19 ms 9632 KB Output is correct
10 Correct 28 ms 9632 KB Output is correct
11 Correct 28 ms 9632 KB Output is correct
12 Correct 29 ms 9836 KB Output is correct
13 Correct 76 ms 10104 KB Output is correct
14 Correct 55 ms 10488 KB Output is correct
15 Correct 66 ms 10872 KB Output is correct
16 Execution timed out 112 ms 12788 KB Time limit exceeded
17 Execution timed out 252 ms 12912 KB Time limit exceeded
18 Execution timed out 30 ms 12912 KB Time limit exceeded (wall clock)
19 Execution timed out 30 ms 12912 KB Time limit exceeded (wall clock)
20 Execution timed out 35 ms 12912 KB Time limit exceeded (wall clock)