# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
82049 | duality | Printed Circuit Board (CEOI12_circuit) | C++11 | 120 ms | 8852 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
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 update(int s,int e,int as,int ae,int i,pair<pii,pii> &p) {
if ((s > ae) || (e < as)) return 0;
else if ((s >= as) && (e <= ae)) {
if (comp(p,tree[i],s,e)) tree[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) {
if (s == e) ans[s] = tree[i];
else {
int mid = (s+e) / 2;
if (comp(tree[i],tree[2*i+1],s,mid)) tree[2*i+1] = tree[i];
if (comp(tree[i],tree[2*i+2],mid+1,e)) tree[2*i+2] = tree[i];
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(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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |