#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
circuit.cpp: In function 'int main()':
circuit.cpp:122: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:126: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:127: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:101:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&N);
~~~~~^~~~~~~~~
circuit.cpp:103: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]);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
4472 KB |
Output is correct |
2 |
Correct |
6 ms |
4596 KB |
Output is correct |
3 |
Correct |
7 ms |
4924 KB |
Output is correct |
4 |
Correct |
8 ms |
4924 KB |
Output is correct |
5 |
Correct |
15 ms |
5164 KB |
Output is correct |
6 |
Correct |
14 ms |
5164 KB |
Output is correct |
7 |
Correct |
26 ms |
5560 KB |
Output is correct |
8 |
Correct |
16 ms |
5560 KB |
Output is correct |
9 |
Correct |
11 ms |
5560 KB |
Output is correct |
10 |
Correct |
14 ms |
5560 KB |
Output is correct |
11 |
Correct |
15 ms |
5560 KB |
Output is correct |
12 |
Correct |
18 ms |
5628 KB |
Output is correct |
13 |
Correct |
55 ms |
6012 KB |
Output is correct |
14 |
Correct |
44 ms |
6392 KB |
Output is correct |
15 |
Correct |
39 ms |
6772 KB |
Output is correct |
16 |
Correct |
85 ms |
8692 KB |
Output is correct |
17 |
Execution timed out |
120 ms |
8852 KB |
Time limit exceeded |
18 |
Execution timed out |
28 ms |
8852 KB |
Time limit exceeded (wall clock) |
19 |
Execution timed out |
27 ms |
8852 KB |
Time limit exceeded (wall clock) |
20 |
Execution timed out |
55 ms |
8852 KB |
Time limit exceeded (wall clock) |